leetcode

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

0328.cpp (413B)


      1 class Solution {
      2   public:
      3     ListNode *oddEvenList(ListNode *head) {
      4         if (!head) return nullptr;
      5 
      6         ListNode *h, *t, *p;
      7         t = h = new ListNode();
      8 
      9         for (p = head; p && p->next;) {
     10             t = t->next = p->next;
     11             p->next = p->next->next;
     12             if (p->next) p = p->next;
     13         }
     14         p->next = h->next;
     15         t->next = nullptr;
     16         return head;
     17     }
     18 };