Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e184c13

Browse files
committed
Update No206
1 parent ab64167 commit e184c13

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

leetcode/LinkedList/No206.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,25 @@ public ListNode reverseList01(ListNode head) {
2727
head.next = null;
2828
return newList;
2929
}
30+
//三指针解决、
31+
public ListNode reverseList(ListNode head) {
32+
if(head == null){
33+
return null;
34+
}
35+
ListNode current = head;
36+
ListNode pre = null;
37+
ListNode newHead = null;
38+
while(current != null){
39+
ListNode next = current.next;
40+
if(next == null){
41+
newHead = current;
42+
}
43+
current.next = pre;
44+
pre = current;
45+
current = next;
46+
}
47+
return newHead;
48+
}
49+
50+
3051
}

0 commit comments

Comments
 (0)