File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ // class ListNode {
2+ // val: number
3+ // next: ListNode | null
4+ // constructor(val?: number, next?: ListNode | null) {
5+ // this.val = (val===undefined ? 0 : val)
6+ // this.next = (next===undefined ? null : next)
7+ // }
8+ // }
9+
10+ // @leet start
11+ /**
12+ * Definition for singly-linked list.
13+ * class ListNode {
14+ * val: number
15+ * next: ListNode | null
16+ * constructor(val?: number, next?: ListNode | null) {
17+ * this.val = (val===undefined ? 0 : val)
18+ * this.next = (next===undefined ? null : next)
19+ * }
20+ * }
21+ */
22+
23+ function deleteDuplicates ( _head : ListNode | null ) : ListNode | null {
24+ let head = _head ;
25+
26+ while ( head && head . next ) {
27+ /** skip the next node if val is eqal */
28+ if ( head . val === head . next . val ) head . next = head . next . next ;
29+ else head = head . next
30+ }
31+
32+ return _head ;
33+ } ;
34+ // @leet end
You can’t perform that action at this time.
0 commit comments