leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0024.cpp (376B)


      1 class Solution {
      2   public:
      3     ListNode *swapPairs(ListNode *head) {
      4         ListNode *d = new ListNode(-1, head);
      5         for (ListNode *p = d; p->next && p->next->next;) {
      6             ListNode *t = p->next;
      7             p->next = p->next->next;
      8             t->next = p->next->next;
      9             p->next->next = t;
     10             p = t;
     11         }
     12         return d->next;
     13     }
     14 };