LC24. Swap Nodes in Pairs 작성일 2019-06-02 https://leetcode.com/problems/swap-nodes-in-pairs/ 링크드 리스트, 방금 푼 문제를 교훈삼아 Two-Point를 전진시켰다. 12345678910111213141516171819202122232425/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* swapPairs(ListNode* head) { ListNode vroot(0); vroot.next=head; for(auto cur = head, prev = &vroot; cur && cur->next ; cur=cur->next, prev=prev->next->next) { ListNode* odd = cur; ListNode* even = cur->next; odd->next = even->next; prev->next = even; even->next = odd; } return vroot.next; } };