鏈表反轉(zhuǎn)主要的思路是交換前后兩個(gè)指針
private static Node reverseListNode(Node head) {
if (head == null || head.getNext() == null) {
return head;
}
Node pre = null;
Node cur = head;
Node next = null;
while (cur != null) {
next = cur.getNext();
cur.setNext(pre);
pre = cur;
cur = next;
}
return pre;
}