Skip to content

Commit

Permalink
update cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Feb 27, 2024
1 parent 13490c5 commit 6de37b3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doc/cheatsheet/linked_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,34 @@ class LinkedList:

### 1-1) Basic OP


#### 1-1-0) Remove Nth node from end
```java
// java
// LC 19

// ...
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode fast = dummy;
ListNode slow = dummy;

for (int i = 1; i <= n+1; i++){
//System.out.println("i = " + i);
fast = fast.next;
}

// move fast and slow pointers on the same time
while (fast != null){
fast = fast.next;
slow = slow.next;
}

// NOTE here
slow.next = slow.next.next;
// ...
```

#### 1-1-1) transversal linked list

#### 1-1-2) plus one on linked list
Expand Down

0 comments on commit 6de37b3

Please sign in to comment.