/**
* @Author:Aliyang
* @Data: Created in 下午10:38 18-6-16
* swap-nodes-in-pairs:我的解法
* 思路:同T125,更简单
**/
public class T126 {
public static class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
public ListNode swapPairs(ListNode head) {
int len=0;
ListNode tmpHead=head;
while (tmpHead!=null){
len++;
tmpHead=tmpHead.next;
}
return reverse(head,len,2);
}
private ListNode reverse(ListNode head,int n,int k){
if (n