Skip to content

Commit 85f04be

Browse files
author
Tushar Borole
committed
80. Remove Duplicates from Sorted Array II
1 parent 1704c9d commit 85f04be

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
| 39 | [Combination Sum](https://leetcode.com/problems/combination-sum/) | [combination_sum.js](combination_sum.js) | 72 ms | 35.8 MB | Medium |
6868
| 40 | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii/) | [combination_sum_II.js](combination_sum_II.js) | 84 ms | 37.6 MB | Medium |
6969
| 46 | [Permutations](https://leetcode.com/problems/permutations/) | [permutations.js](permutations.js) | 88 ms | 37.6 MB | Medium |
70+
| 80 | [Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) | [remove_duplicates_from_sorted_array_II.js](remove_duplicates_from_sorted_array_II.js) | 64 ms | 35.8 MB | Medium |
7071

7172

7273
## Others
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var removeDuplicates = function(nums) {
6+
let duplicateCounter = 0;
7+
for (let i = 0; i < nums.length; i++) {
8+
if (nums[i] === nums[i + 1]) {
9+
duplicateCounter++;
10+
} else {
11+
duplicateCounter = 0;
12+
}
13+
14+
if (duplicateCounter > 1) {
15+
nums.splice(i, 1);
16+
i--;
17+
}
18+
}
19+
};
20+
21+
removeDuplicates([1, 1, 1, 2, 2, 3]);

0 commit comments

Comments
 (0)