leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0328.cpp (413B)
0 class Solution {
1 public:
2 ListNode *oddEvenList(ListNode *head) {
3 if (!head) return nullptr;
5 ListNode *h, *t, *p;
6 t = h = new ListNode();
8 for (p = head; p && p->next;) {
9 t = t->next = p->next;
10 p->next = p->next->next;
11 if (p->next) p = p->next;
12 }
13 p->next = h->next;
14 t->next = nullptr;
15 return head;
16 }
17 };