美文网首页
27. Remove Element

27. Remove Element

作者: becauseyou_90cd | 来源:发表于2018-07-31 22:15 被阅读0次

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

    解题思路:

    1. nums[res++] == nums[i] when nums[i] == val;

    代码:
    class Solution {
    public int removeElement(int[] nums, int val) {

        if(nums == null) return 0;
        int res = 0;
        for(int i = 0; i < nums.length; i++){
            if(nums[i] != val)
                nums[res++] = nums[i];    
        }
        return res;
    }
    

    }

    相关文章

      网友评论

          本文标题:27. Remove Element

          本文链接:https://www.haomeiwen.com/subject/kxthvftx.html