/**
* 单链表反转
* @param node 头结点
* @return 翻转后的头结点,原链表尾节点
*/
public static Node reverseList(Node node) {
Node currNode = node;
Node preNode = null;
while (currNode != null) {
Node nextNode = currNode.next;
currNode.next = preNode;
preNode = currNode;
currNode = nextNode;
}
return preNode;
}
网友评论