Javascript solution O(n)


  • 0
    P

    //Cut elements from back
    var removeElement = function(nums, val) {
    for( var i = nums.length -1; i >= 0 ; i--) {
    if(nums[i] === val) nums.splice(i,1)
    }
    return nums.length;
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.