class Solution {
public:
ListNode* swapPairs(ListNode* head) {
ListNode * cur = head;
while(cur!=NULL && cur->next!=NULL){
int tmp = cur->val;
cur->val = cur->next->val;
cur->next->val = tmp;
cur = cur->next->next;
}
return head;
}
};
leetcode 24. Swap Nodes in Pairs
最新推荐文章于 2022-03-08 20:04:47 发布