首页 > 其他 > 详细

【Leetcode-easy】Remove Element

时间:2015-11-25 22:22:00      阅读:303      评论:0      收藏:0      [点我收藏+]

思路:遍历数组,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 }

 

【Leetcode-easy】Remove Element

原文:http://www.cnblogs.com/scecit/p/4995841.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!