File tree 1 file changed +5
-5
lines changed
src/main/java/com/fishercoder/solutions/firstthousand
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -75,10 +75,10 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
75
75
public static class Solution3 {
76
76
//a more concise version using the same idea
77
77
public ListNode removeNthFromEnd (ListNode head , int n ) {
78
- ListNode dummy = new ListNode (-1 );
79
- dummy .next = head ;
80
- ListNode slow = dummy ;
81
- ListNode fast = dummy ;
78
+ ListNode pre = new ListNode (-1 );
79
+ pre .next = head ;
80
+ ListNode slow = pre ;
81
+ ListNode fast = pre ;
82
82
while (fast .next != null ) {
83
83
if (n <= 0 ) {
84
84
slow = slow .next ;
@@ -89,7 +89,7 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
89
89
if (slow .next != null ) {
90
90
slow .next = slow .next .next ;
91
91
}
92
- return dummy .next ;
92
+ return pre .next ;
93
93
}
94
94
}
95
95
}
You can’t perform that action at this time.
0 commit comments