Skip to content

Commit 3f1d38e

Browse files
committed
feat: add js solution to lc problem: no.82
1 parent de6d44a commit 3f1d38e

File tree

6 files changed

+118
-10
lines changed

6 files changed

+118
-10
lines changed

.metals/metals.h2.db

-5.13 MB
Binary file not shown.

.metals/metals.lock.db

-6
This file was deleted.

.metals/metals.log

-4
This file was deleted.

solution/0000-0099/0082.Remove Duplicates from Sorted List II/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,47 @@ public:
134134
};
135135
```
136136
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+
137178
### **...**
138179

139180
```

solution/0000-0099/0082.Remove Duplicates from Sorted List II/README_EN.md

+41
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,47 @@ public:
122122
};
123123
```
124124
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+
125166
### **...**
126167

127168
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
};

0 commit comments

Comments
 (0)