Skip to content

Commit f103634

Browse files
author
laileon
committed
simplfy
1 parent 651faf1 commit f103634

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/com/blankj/custom/structure/ListNode.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ public ListNode(int val, ListNode next) {
1414
}
1515

1616
//单向链表, 从前往后反转各个结点的指针域的指向
17-
//非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点一次插入到头部
17+
//非递归实现很简单,只需要遍历一遍链表,在遍历过程中,把遍历的节点依次插入到头部
1818
public ListNode reverseList(ListNode head) {
19-
ListNode prev = null;
19+
ListNode curr = null;
2020
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后移一位
2526
}
26-
return prev;
27+
return curr;
2728
}
2829

2930
}

0 commit comments

Comments
 (0)