File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
src/com/blankj/custom/structure Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,17 @@ public ListNode(int val, ListNode next) {
14
14
}
15
15
16
16
//单向链表, 从前往后反转各个结点的指针域的指向
17
- //非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点一次插入到头部
17
+ //非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点依次插入到头部
18
18
public ListNode reverseList (ListNode head ) {
19
- ListNode prev = null ;
19
+ ListNode curr = null ;
20
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后移一位
21
+ curr = head ; //prev后移一位
22
+ head = head .next ;
23
+ head .next = curr ; //head指向head后面那个
24
+ // ListNode tmp = head.next; //tmp赋值为head后面的节点
25
+ // head = tmp; //head后移一位
25
26
}
26
- return prev ;
27
+ return curr ;
27
28
}
28
29
29
30
}
You can’t perform that action at this time.
0 commit comments