Skip to content

Commit f7f7d6e

Browse files
feat(dsa): solve remove duplicates from sorted array using two-pointer approach
1 parent 2f7a8f0 commit f7f7d6e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Topic6/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,14 @@ function reverse(i, j) {
7878
j--;
7979
}
8080
}
81+
82+
// Remove duplicates from sorted array using two pointers algorithm
83+
let nums1 = [1, 1, 2, 2, 3, 4, 4];
84+
let j1 = 1;
85+
for (let i = 0; i < nums1.length - 1; i++) {
86+
if (nums1[i] != nums1[i + 1]) {
87+
nums1[j] = nums1[i + 1];
88+
j1++;
89+
}
90+
}
91+
return j1;

0 commit comments

Comments
 (0)