标签:
Visualize the unzip process.
class Solution { public: ListNode* oddEvenList(ListNode* head) { if (!head || !head->next) return head; ListNode *pOddHead = head, *pEvenHead = head->next; ListNode *pOddTail = pOddHead, *pEvenTail = pEvenHead; ListNode *pOddLast = pOddTail; while (pOddTail) { ListNode *pNxtOdd = pOddTail->next ? pOddTail->next->next : nullptr; ListNode *pNxtEven = (!pEvenTail || !pEvenTail->next) ? nullptr : pEvenTail->next->next; pOddTail->next = pNxtOdd; if(pEvenTail) pEvenTail->next = pNxtEven; pOddLast = pOddTail; pOddTail = pNxtOdd; pEvenTail = pNxtEven; } pOddLast->next = pEvenHead; return pOddHead; } };
LeetCode "Odd Even Linked List"
标签:
原文地址:http://www.cnblogs.com/tonix/p/5152784.html