public static ListNode swapPairs(ListNode head) {
ListNode pre = null, cur =null;
if(head == null){
return head;
}else {
pre = head;
cur = head.next;
}
while(cur!=null) {
int tmp = pre.val;
pre.val = cur.val;
cur.val = tmp;
pre = cur.next;
if(pre != null) {
cur = pre.next;
}else{
cur = null;
}
}
return head;
}
24. Swap Nodes in Pairs
最新推荐文章于 2024-10-13 15:10:00 发布