Question:27 why my answer is wrong?I think is right,this is my code.


  • -1
    B

    public class Solution {
    public int removeElement(int[] nums, int val) {
    int m = 0;
    int len = nums.length;
    if(nums.length==0)
    {
    return 0;
    }
    for(int i=0;i<len;i++)
    {
    if(nums[i]==val)
    {
    m = m+1;
    int j=0;
    while(j+1<len)
    {
    nums[j]=nums[j+1];
    j++;
    }
    len = len-1;
    }
    }

    	if(nums[len]==val)
    	{
    		m = m+1;	
    	}
    	return nums.length-m;
        
    }
    

    }


Log in to reply
 

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