Given an array and a value, remove all instances of that value in place and return the new length.

Do not allocate extra space for another array, you must do this in place with constant memory.

The order of elements can be changed. It doesn't matter what you leave beyond the new length.

并不懂这道题想要干嘛,题意说的不是很清楚,感觉没多大意义。用另一个pointer就能把不同于val的数读出来。。。

 

public class Solution {
    public int removeElement(int[] nums, int val) {
        int index=0;
    for(int i=0;i<nums.length;i++)
    {
        if(nums[i]!=val)
        {
            nums[index++]=nums[i];
        }
    }
    return index;
}
}

 

posted on 2016-09-11 14:25  Machelsky  阅读(102)  评论(0)    收藏  举报