Remove Element - Incorrect judgement with Javascript?


  • -1
    S

    my codes are as below:

    var removeElement = function(nums, val) {
        for(var i=0,newLen=nums.length;i<nums.length;i++){
            if(nums[i]==val){
                newLen --;
            }
        }
        return newLen;
    };
    
    var removeElement = function(nums, val) {
         return nums.filter(function(e){
             return e != val;
         }).length;
     }
    

    Did I really get the wrong comprehension of this question or is the judgement system malfunctioning? I tried both of my solutions and the system just responded WRONG ANSWER... Isn't the question asking me to compute the new length of the filtered array???
    Please help point out any mistake if any, Thanks!


Log in to reply
 

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