https://leetcode.com/problems/remove-element/description/
解题思路:
- 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;
}
}
网友评论