File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 35
35
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
36
36
67|[ Add Binary] ( ./0067-add-binary.js ) |Easy|
37
37
73|[ Set Matrix Zeroes] ( ./0073-set-matrix-zeroes.js ) |Medium|
38
+ 83|[ Remove Duplicates from Sorted List] ( ./0083-remove-duplicates-from-sorted-list.js ) |Easy|
38
39
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
39
40
118|[ Pascal's Triangle] ( ./0118-pascals-triangle.js ) |Easy|
40
41
119|[ Pascal's Triangle II] ( ./0119-pascals-triangle-ii.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 83. Remove Duplicates from Sorted List
3
+ * https://leetcode.com/problems/remove-duplicates-from-sorted-list/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given the head of a sorted linked list, delete all duplicates such that each
7
+ * element appears only once. Return the linked list sorted as well.
8
+ */
9
+
10
+ /**
11
+ * Definition for singly-linked list.
12
+ * function ListNode(val, next) {
13
+ * this.val = (val===undefined ? 0 : val)
14
+ * this.next = (next===undefined ? null : next)
15
+ * }
16
+ */
17
+ /**
18
+ * @param {ListNode } head
19
+ * @return {ListNode }
20
+ */
21
+ var deleteDuplicates = function ( head ) {
22
+ const result = new ListNode ( ) ;
23
+ const set = new Set ( ) ;
24
+ let tail = result ;
25
+
26
+ while ( head ) {
27
+ if ( ! set . has ( head . val ) ) {
28
+ tail . next = new ListNode ( head . val ) ;
29
+ tail = tail . next ;
30
+ }
31
+
32
+ set . add ( head . val ) ;
33
+
34
+ head = head . next ;
35
+ }
36
+
37
+ return result . next ;
38
+ } ;
You can’t perform that action at this time.
0 commit comments