码迷,mamicode.com
首页 > 其他好文 > 详细

27. Remove Element

时间:2017-07-01 20:11:18      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:rip   public   []   remove   for   problems   com   element   esc   

https://leetcode.com/problems/remove-element/#/description

 

public class Solution {
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int len = nums.length, index = 0;
        for (int num : nums) {
            if (num != val) {
                nums[index++] = num;
                
            } else {
                len--;
            }
        }
        return len;
    }
}

  

27. Remove Element

标签:rip   public   []   remove   for   problems   com   element   esc   

原文地址:http://www.cnblogs.com/apanda009/p/7103181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!