Javascript solution O(n)


  • 0
    var removeElement = function(nums, val) {
        let i = 0;
          while(i < nums.length) {
            if (nums[i] === val) {
              nums.splice(i, 1);
              continue;
            } 
            i++;
          }
          return nums.length;
    };

Log in to reply
 

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