java实现的LeetCode中交换链表中相邻的值
public class SwapNodes{
public ListNode swapPairs(ListNode head){
ListNode aidNode=new ListNode(0);
aidNode.next=head;
ListNode currentNode=aidNode;
while(currentNode.next!=null&¤tNode.next.next!=null){
ListNode firstNode=currentNode.next;
ListNode secondNode=currentNode.next.next;
firstNode.next=secondNode.next;
currentNode.next=secondNode;
currentNode.next.next=firstNode;
currentNode=currentNode.next.next;
}
return aidNode.next;
}
class ListNode{
int value;
ListNode next;
public ListNode(int value){
this.value=value;
}
}
}