标签:app 技术 play opened gif head lap air style
要求
示例
实现
1 struct ListNode { 2 int val; 3 ListNode *next; 4 ListNode(int x) : val(x), next(NULL) {} 5 }; 6 7 class Solution { 8 public: 9 ListNode* swapPairs(ListNode* head) { 10 ListNode* dummyHead = new ListNode(0); 11 dummyHead->next = head; 12 13 ListNode* p = dummyHead; 14 while( p->next && p->next->next ){ 15 ListNode* node1 = p->next; 16 ListNode* node2 = node1->next; 17 ListNode* next = node2->next; 18 19 node2->next = node1; 20 node1->next = next; 21 p->next = node2; 22 23 p = node1; 24 } 25 26 ListNode* retNode = dummyHead->next; 27 delete dummyHead; 28 29 return retNode; 30 } 31 };
相关
[刷题] LeetCode 24 Swap Nodes in Paris
标签:app 技术 play opened gif head lap air style
原文地址:https://www.cnblogs.com/cxc1357/p/12640484.html