Skip to content

Commit 4e9bb36

Browse files
authored
Merge pull request neetcode-gh#1418 from imevanc/Create-83-Remove-Duplicates-From-Sorted-List
Create: 83-Remove-Duplicates-From-Sorted-List.js
2 parents aa783df + c4b5b0e commit 4e9bb36

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* https://leetcode.com/problems/remove-duplicates-from-sorted-list/
3+
* Definition for singly-linked list.
4+
* function ListNode(val, next) {
5+
* this.val = (val===undefined ? 0 : val)
6+
* this.next = (next===undefined ? null : next)
7+
* }
8+
*/
9+
/**
10+
* @param {ListNode} head
11+
* @return {ListNode}
12+
*/
13+
var deleteDuplicates = function (head) {
14+
let cur = head;
15+
while (cur != null && cur.next != null) {
16+
if (cur.next.val === cur.val) {
17+
cur.next = cur.next.next;
18+
} else {
19+
cur = cur.next;
20+
}
21+
}
22+
return head;
23+
};

0 commit comments

Comments
 (0)