We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 651faf1 commit f103634Copy full SHA for f103634
src/com/blankj/custom/structure/ListNode.java
@@ -14,16 +14,17 @@ public ListNode(int val, ListNode next) {
14
}
15
16
//单向链表, 从前往后反转各个结点的指针域的指向
17
- //非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点一次插入到头部
+ //非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点依次插入到头部
18
public ListNode reverseList(ListNode head) {
19
- ListNode prev = null;
+ ListNode curr = null;
20
while (head != null) { //如果当前节点不为空
21
- ListNode tmp = head.next; //tmp赋值为head后面的节点
22
- head.next = prev; //head指向head后面那个
23
- prev = head; //prev后移一位
24
- head = tmp; //head后移一位
+ curr = head; //prev后移一位
+ head = head.next;
+ head.next = curr; //head指向head后面那个
+// ListNode tmp = head.next; //tmp赋值为head后面的节点
25
+// head = tmp; //head后移一位
26
- return prev;
27
+ return curr;
28
29
30
0 commit comments