Back to course home
0% completed
Vote For New Content
Easy solution in JS
CJ
Jun 9, 2024
class Solution { moveElements(arr) { let read = 0; let lastUnique = 0; while (read < arr.length) { if (arr[read] !== arr[lastUnique]) { // found new unique value const write = Math.min(lastUnique + 1, read); arr[write] = arr[read]; lastUnique = write; } read += 1; } return lastUnique + 1; // lengh = lastIndex + 1 } }
0
0
Comments
Comments
On this page
Problem Statement
Try it yourself