We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7144043 commit c8d54f7Copy full SHA for c8d54f7
javascript/26-Remove-Duplicates-from-Sorted-Array.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * Linear
3
+ * Time O(N) | Space O(1)
4
+ * https://leetcode.com/problems/remove-duplicates-from-sorted-array/
5
+ * @param {number[]} nums
6
+ * @return {number}
7
+ */
8
+var removeDuplicates = function(nums) {
9
+
10
+ let left = 0;
11
+ let right = 1;
12
+ let delCount = 0;
13
14
+ while (right <= nums.length) {
15
+ if (nums[left] === nums[right]) {
16
+ right++;
17
+ delCount++;
18
+ } else {
19
+ nums.splice(left + 1, delCount);
20
+ delCount = 0;
21
+ left++;
22
+ right = left + 1;
23
+ }
24
25
+};
0 commit comments