题目:
class Solution {
public ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode cur = head;
while(cur!=null){
ListNode node = cur.next;
cur.next = pre;
pre = cur;
cur = node;
}
return pre;
}
}
class Solution {
public ListNode swapPairs(ListNode head) {
ListNode pre = new ListNode(0);
ListNode node = pre;
ListNode cur = head;
while(cur!=null&&cur.next!=null){
ListNode temp = cur.next;
ListNode aft = temp.next;
pre.next = temp;
temp.next = cur;
cur.next = aft;
pre = cur;
cur = aft;
}
pre.next = cur;
return node.next;
}
}