Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lcci/02.01.Remove Duplicate Node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ class Solution {
}
```

### **JavaScript**

```javascript
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var removeDuplicateNodes = function(head) {
if (head == null || head.next == null) return head;
const cache = new Set([]);
cache.add(head.val);
let cur = head, fast = head.next;
while (fast !== null) {
if (!cache.has(fast.val)) {
cur.next = fast;
cur = cur.next;
cache.add(fast.val);
}
fast = fast.next;
}
cur.next = null;
return head;
};
```

### **...**

```
Expand Down
32 changes: 32 additions & 0 deletions lcci/02.01.Remove Duplicate Node/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,38 @@ class Solution {
}
```

### **JavaScript**

```javascript
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var removeDuplicateNodes = function(head) {
if (head == null || head.next == null) return head;
const cache = new Set([]);
cache.add(head.val);
let cur = head, fast = head.next;
while (fast !== null) {
if (!cache.has(fast.val)) {
cur.next = fast;
cur = cur.next;
cache.add(fast.val);
}
fast = fast.next;
}
cur.next = null;
return head;
};
```

### **...**

```
Expand Down
27 changes: 27 additions & 0 deletions lcci/02.01.Remove Duplicate Node/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var removeDuplicateNodes = function(head) {
if (head == null || head.next == null) return head;
const cache = new Set([]);
cache.add(head.val);
let cur = head, fast = head.next;
while (fast !== null) {
if (!cache.has(fast.val)) {
cur.next = fast;
cur = cur.next;
cache.add(fast.val);
}
fast = fast.next;
}
cur.next = null;
return head;
};