Skip to content

Commit 1913e84

Browse files
author
钱毓婷
committed
feat: add solution of Remove Duplicates from Sorted List(083) with javascript.
1 parent 4728ebf commit 1913e84

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
| [068][068-question] | [Text Justification][068-tips] | [Hard][H] | [][068-java] | | |
7272
| [069][069-question] | [Sqrt(x)][069-tips] | [Easy][E] | [][069-java] | [][069-js] | [][069-kotlin] |
7373
| [070][070-question] | [Climbing Stairs][070-tips] | [Easy][E] | [][070-java] | [][070-js] | [][070-kotlin] |
74-
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [Easy][E] | [][083-java] | | [][083-kotlin] |
74+
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [Easy][E] | [][083-java] | [][083-js] | [][083-kotlin] |
7575
| [088][088-question] | [Merge Sorted Array][088-tips] | [Easy][E] | [][088-java] | | [][088-kotlin] |
7676
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | | [][100-kotlin] |
7777
| [101][101-question] | [Symmetric Tree][101-tips] | [Easy][E] | [][101-java] | | [][101-kotlin] |
@@ -377,6 +377,7 @@
377377
[067-js]: ./src/_067/Solution.js
378378
[069-js]: ./src/_069/Solution.js
379379
[070-js]: ./src/_070/Solution.js
380+
[083-js]: ./src/_083/Solution.js
380381
[226-js]: ./src/_226/Solution.js
381382
[561-js]: ./src/_561/Solution.js
382383
[643-js]: ./src/_643/Solution.js

src/_083/Solution.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {ListNode}
11+
*/
12+
var deleteDuplicates = function(head) {
13+
if(head === null || head.val === null || head.next === null) {
14+
return head
15+
}
16+
var current = head
17+
var currentVal = head.val
18+
while(true) {
19+
if(current.next === null) {
20+
break;
21+
}
22+
if(current.next.val === currentVal) {
23+
current.next = current.next.next
24+
} else {
25+
currentVal = current.next.val
26+
current = current.next
27+
}
28+
}
29+
return head
30+
};

tips/083/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,28 @@ class Solution {
6161
}
6262
```
6363

64-
64+
javascript
65+
```javascript
66+
var deleteDuplicates = function(head) {
67+
if(head === null || head.val === null || head.next === null) {
68+
return head
69+
}
70+
var current = head
71+
var currentVal = head.val
72+
while(true) {
73+
if(current.next === null) {
74+
break;
75+
}
76+
if(current.next.val === currentVal) {
77+
current.next = current.next.next
78+
} else {
79+
currentVal = current.next.val
80+
current = current.next
81+
}
82+
}
83+
return head
84+
};
85+
```
6586
## 结语
6687

6788
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]

0 commit comments

Comments
 (0)