机器学习之路漫漫
MLEW(Maching Learning & Endless Way)

导航

 

思路:遍历数组,count保存下一个元素的位置,如果不与该元素相同,那么将该数保存在count位置,并且count++,否则,继续遍历。

 1 public int removeElement(int[] nums, int val) {
 2        int count=0;
 3        for(int i=0;i<nums.length;i++){
 4            if(nums[i]!=val){
 5                nums[count]=nums[i];
 6                count++;
 7            }
 8        }
 9        return count;
10 }

 

posted on 2015-11-25 20:35  suchang  阅读(188)  评论(0编辑  收藏  举报