leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1721.cpp (384B)
0 class Solution { 1 public: 2 ListNode *swapNodes(ListNode *head, int k) { 3 ListNode *tmp = head, *first; 4 while (--k) 5 tmp = tmp->next; 6 first = tmp; 7 8 ListNode *second = head; 9 tmp = tmp->next; 10 while (tmp) 11 tmp = tmp->next, second = second->next; 12 swap(first->val, second->val); 13 return head; 14 } 15 };