fueanta

Remove duplicates from a sorted array.

Jul 25th, 2019
197
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @param {number[]} nums
  3.  * @return {number}
  4.  */
  5. var removeDuplicates = nums => {
  6.   for (let i = 0; i < nums.length - 1; ) {
  7.     if (nums[i] === nums[i + 1]) {
  8.       nums.splice(i, 1);
  9.       continue;
  10.     }
  11.     i++;
  12.   }
  13.   return nums.length;
  14. };
RAW Paste Data