LeetCode 26 – Remove Duplicates from Sorted Array

Here is my solution to Remove Duplicates from Sorted Array problem in JavaScript

/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function(nums) {    
    let i=0;
    
    while (i<nums.length-1) {
        if (nums[i] === nums[i+1]) {
            nums.splice(i+1, 1);
        } else {
            i++;
        }
    }
    
    return nums.length;
};

Results

Runtime: 108 ms, faster than 33.69% of JavaScript online submissions for Remove Duplicates from Sorted Array.Memory Usage: 40.6 MB, less than 89.66% of JavaScript online submissions for Remove Duplicates from Sorted Array.