Skip to content

Commit 6de37b3

Browse files
committed
update cheatsheet
1 parent 13490c5 commit 6de37b3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/cheatsheet/linked_list.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,34 @@ class LinkedList:
289289

290290
### 1-1) Basic OP
291291

292+
293+
#### 1-1-0) Remove Nth node from end
294+
```java
295+
// java
296+
// LC 19
297+
298+
// ...
299+
ListNode dummy = new ListNode(0);
300+
dummy.next = head;
301+
ListNode fast = dummy;
302+
ListNode slow = dummy;
303+
304+
for (int i = 1; i <= n+1; i++){
305+
//System.out.println("i = " + i);
306+
fast = fast.next;
307+
}
308+
309+
// move fast and slow pointers on the same time
310+
while (fast != null){
311+
fast = fast.next;
312+
slow = slow.next;
313+
}
314+
315+
// NOTE here
316+
slow.next = slow.next.next;
317+
// ...
318+
```
319+
292320
#### 1-1-1) transversal linked list
293321

294322
#### 1-1-2) plus one on linked list

0 commit comments

Comments
 (0)