/**
* 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 *ptr=head;
while(ptr!=NULL&&ptr->next!=NULL){
swap(ptr->val,ptr->next->val);
ptr=ptr->next->next;
}
return head;
}
};
LeetCode - 24 Swap Nodes in Pairs
最新推荐文章于 2020-04-03 20:41:14 发布