/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
// 先交换1 2 然后再交换3 一次类推
ListNode result = new ListNode();
result.next =head;
while(head !=null && head.next !=null) {
ListNode k1 = result.next;
ListNode k2 = head.next;
// 交换
result.next =k2;
head.next =k2.next;
k2.next =k1;
}
return result.next;
}
}