Skip to content

Commit 7f36bb4

Browse files
update 19
1 parent 25db1bb commit 7f36bb4

File tree

1 file changed

+5
-5
lines changed
  • src/main/java/com/fishercoder/solutions/firstthousand

1 file changed

+5
-5
lines changed

src/main/java/com/fishercoder/solutions/firstthousand/_19.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
7575
public static class Solution3 {
7676
//a more concise version using the same idea
7777
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;
8282
while (fast.next != null) {
8383
if (n <= 0) {
8484
slow = slow.next;
@@ -89,7 +89,7 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
8989
if (slow.next != null) {
9090
slow.next = slow.next.next;
9191
}
92-
return dummy.next;
92+
return pre.next;
9393
}
9494
}
9595
}

0 commit comments

Comments
 (0)