File tree 6 files changed +118
-10
lines changed
solution/0000-0099/0082.Remove Duplicates from Sorted List II
6 files changed +118
-10
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -134,6 +134,47 @@ public:
134
134
};
135
135
```
136
136
137
+ ### **JavaScript**
138
+
139
+ ```js
140
+ /**
141
+ * Definition for singly-linked list.
142
+ * function ListNode(val, next) {
143
+ * this.val = (val===undefined ? 0 : val)
144
+ * this.next = (next===undefined ? null : next)
145
+ * }
146
+ */
147
+ /**
148
+ * @param {ListNode} head
149
+ * @return {ListNode}
150
+ */
151
+ var deleteDuplicates = function (head) {
152
+ let cur = head;
153
+ let pre = new ListNode(0);
154
+ pre.next = head;
155
+ let dummy = pre;
156
+ let rep = false;
157
+ if (!head || !head.next) {
158
+ return head;
159
+ }
160
+ while (cur) {
161
+ while (cur.next && cur.val == cur.next.val) {
162
+ cur = cur.next;
163
+ rep = true;
164
+ }
165
+ if (rep) {
166
+ pre.next = cur.next;
167
+ cur = cur.next;
168
+ } else {
169
+ pre = cur;
170
+ cur = cur.next;
171
+ }
172
+ rep = false;
173
+ }
174
+ return dummy.next;
175
+ };
176
+ ```
177
+
137
178
### ** ...**
138
179
139
180
```
Original file line number Diff line number Diff line change @@ -122,6 +122,47 @@ public:
122
122
};
123
123
```
124
124
125
+ ### **JavaScript**
126
+
127
+ ```js
128
+ /**
129
+ * Definition for singly-linked list.
130
+ * function ListNode(val, next) {
131
+ * this.val = (val===undefined ? 0 : val)
132
+ * this.next = (next===undefined ? null : next)
133
+ * }
134
+ */
135
+ /**
136
+ * @param {ListNode} head
137
+ * @return {ListNode}
138
+ */
139
+ var deleteDuplicates = function (head) {
140
+ let cur = head;
141
+ let pre = new ListNode(0);
142
+ pre.next = head;
143
+ let dummy = pre;
144
+ let rep = false;
145
+ if (!head || !head.next) {
146
+ return head;
147
+ }
148
+ while (cur) {
149
+ while (cur.next && cur.val == cur.next.val) {
150
+ cur = cur.next;
151
+ rep = true;
152
+ }
153
+ if (rep) {
154
+ pre.next = cur.next;
155
+ cur = cur.next;
156
+ } else {
157
+ pre = cur;
158
+ cur = cur.next;
159
+ }
160
+ rep = false;
161
+ }
162
+ return dummy.next;
163
+ };
164
+ ```
165
+
125
166
### ** ...**
126
167
127
168
```
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val, next) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.next = (next===undefined ? null : next)
6
+ * }
7
+ */
8
+ /**
9
+ * @param {ListNode } head
10
+ * @return {ListNode }
11
+ */
12
+ var deleteDuplicates = function ( head ) {
13
+ let cur = head ;
14
+ let pre = new ListNode ( 0 ) ;
15
+ pre . next = head ;
16
+ let dummy = pre ;
17
+ let rep = false ;
18
+ if ( ! head || ! head . next ) {
19
+ return head ;
20
+ }
21
+ while ( cur ) {
22
+ while ( cur . next && cur . val == cur . next . val ) {
23
+ cur = cur . next ;
24
+ rep = true ;
25
+ }
26
+ if ( rep ) {
27
+ pre . next = cur . next ;
28
+ cur = cur . next ;
29
+ } else {
30
+ pre = cur ;
31
+ cur = cur . next ;
32
+ }
33
+ rep = false ;
34
+ }
35
+ return dummy . next ;
36
+ } ;
You can’t perform that action at this time.
0 commit comments