leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0024.cpp (376B)
0 class Solution {
1 public:
2 ListNode *swapPairs(ListNode *head) {
3 ListNode *d = new ListNode(-1, head);
4 for (ListNode *p = d; p->next && p->next->next;) {
5 ListNode *t = p->next;
6 p->next = p->next->next;
7 t->next = p->next->next;
8 p->next->next = t;
9 p = t;
10 }
11 return d->next;
12 }
13 };