Created
June 2, 2017 09:49
-
-
Save midorikocak/66e9ea1f7ee48753dcd4a4093f0294e0 to your computer and use it in GitHub Desktop.
This is why I hate Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var removeDuplicates = function(nums) { | |
if(nums.length===1) return 1; | |
var i=1; | |
var length = nums.length; | |
var current = nums[0]; | |
var toDelete = []; | |
while(i<length){ | |
if(nums[i]==current){ | |
toDelete.push(i); | |
} | |
else{ | |
current = nums[i]; | |
} | |
i++; | |
} | |
while(toDelete.length) { | |
nums.splice(toDelete.pop(), 1); | |
} | |
return nums.length; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Immutability is your friend.