赞
踩
接着链表。
24.两两交换链表中的节点leetcode24 Swap Nodes in Pairs
class Solution { public: ListNode* swapPairs(ListNode* head) { ListNode*dummyhead=new ListNode(0); dummyhead->next=head; ListNode*cur=dummyhead; while(cur->next!=nullptr&&cur->next->next!=nullptr) { ListNode*tmp=cur->next; ListNode*tmp2=cur->next->next->next; cur->next= cur->next->next; cur->next->next=tmp; cur->next->next->next=tmp2; cur=cur->next->next;<
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。