Skip to content

Commit de6d44a

Browse files
committed
feat: add js solution to leetcode problem: no.86
1 parent 22b7993 commit de6d44a

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

.metals/metals.h2.db

5.13 MB
Binary file not shown.

.metals/metals.lock.db

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#FileLock
2+
#Fri Aug 13 21:54:54 CST 2021
3+
server=localhost\:64970
4+
hostName=localhost
5+
method=file
6+
id=17b3f994b58bce93b6bb4619a065c552a932c9d6848

.metals/metals.log

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2021.08.13 21:00:13 INFO Started: Metals version 0.10.5 in workspace 'D:\github\multi-lc\leetcode' for client Visual Studio Code 1.59.0.
2+
2021.08.13 21:00:15 INFO time: initialize in 1.7s
3+
2021.08.13 21:00:15 WARN Build server is not auto-connectable.
4+
2021.08.13 21:00:15 WARN no build tool detected in workspace 'D:\github\multi-lc\leetcode'. The most common cause for this problem is that the editor was opened in the wrong working directory, for example if you use sbt then the workspace directory should contain build.sbt. 

solution/0000-0099/0086.Partition List/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,48 @@ public:
144144
}
145145
};
146146
```
147+
### **JavaScript**
148+
149+
```js
150+
/**
151+
* Definition for singly-linked list.
152+
* function ListNode(val, next) {
153+
* this.val = (val===undefined ? 0 : val)
154+
* this.next = (next===undefined ? null : next)
155+
* }
156+
*/
157+
/**
158+
* @param {ListNode} head
159+
* @return {ListNode}
160+
*/
161+
var deleteDuplicates = function (head) {
162+
let cur = head;
163+
let pre = new ListNode(0);
164+
pre.next = head;
165+
let dummy = pre;
166+
let rep = false;
167+
if (!head || !head.next) {
168+
return head;
169+
}
170+
while (cur) {
171+
while (cur.next && cur.val == cur.next.val) {
172+
cur = cur.next;
173+
rep = true;
174+
}
175+
if (rep) {
176+
pre.next = cur.next;
177+
cur = cur.next;
178+
} else {
179+
pre = cur;
180+
cur = cur.next;
181+
}
182+
rep = false;
183+
}
184+
return dummy.next;
185+
};
186+
```
187+
188+
147189

148190
### **...**
149191

solution/0000-0099/0086.Partition List/README_EN.md

+38
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,44 @@ public:
132132
}
133133
};
134134
```
135+
### **JavaScript**
136+
137+
```js
138+
/**
139+
* Definition for singly-linked list.
140+
* function ListNode(val, next) {
141+
* this.val = (val===undefined ? 0 : val)
142+
* this.next = (next===undefined ? null : next)
143+
* }
144+
*/
145+
/**
146+
* @param {ListNode} head
147+
* @param {number} x
148+
* @return {ListNode}
149+
*/
150+
var partition = function (head, x) {
151+
152+
if (!head || !head.next) {
153+
return head;
154+
}
155+
const dummy1 = new ListNode(-1), dummy2 = new ListNode(-1);
156+
let cur1 = dummy1, cur2 = dummy2;
157+
let cur = head;
158+
while (cur) {
159+
if (cur.val < x) {
160+
cur1.next = cur;
161+
cur1 = cur1.next;
162+
} else {
163+
cur2.next = cur;
164+
cur2 = cur2.next;
165+
}
166+
cur = cur.next;
167+
}
168+
cur2.next = null;
169+
cur1.next = dummy2.next;
170+
return (dummy1.next);
171+
};
172+
```
135173

136174
### **...**
137175

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
* @param {number} x
11+
* @return {ListNode}
12+
*/
13+
var partition = function (head, x) {
14+
15+
if (!head || !head.next) {
16+
return head;
17+
}
18+
const dummy1 = new ListNode(-1), dummy2 = new ListNode(-1);
19+
let cur1 = dummy1, cur2 = dummy2;
20+
let cur = head;
21+
while (cur) {
22+
if (cur.val < x) {
23+
cur1.next = cur;
24+
cur1 = cur1.next;
25+
} else {
26+
cur2.next = cur;
27+
cur2 = cur2.next;
28+
}
29+
cur = cur.next;
30+
}
31+
cur2.next = null;
32+
cur1.next = dummy2.next;
33+
return (dummy1.next);
34+
};

0 commit comments

Comments
 (0)