We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 25db1bb commit 7f36bb4Copy full SHA for 7f36bb4
src/main/java/com/fishercoder/solutions/firstthousand/_19.java
@@ -75,10 +75,10 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
75
public static class Solution3 {
76
//a more concise version using the same idea
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;
+ ListNode pre = new ListNode(-1);
+ pre.next = head;
+ ListNode slow = pre;
+ ListNode fast = pre;
82
while (fast.next != null) {
83
if (n <= 0) {
84
slow = slow.next;
@@ -89,7 +89,7 @@ public ListNode removeNthFromEnd(ListNode head, int n) {
89
if (slow.next != null) {
90
slow.next = slow.next.next;
91
}
92
- return dummy.next;
+ return pre.next;
93
94
95
0 commit comments