Home LeetCode. 27. Remove Element
Post
Cancel

LeetCode. 27. Remove Element

image

[Link] https://leetcode.com/problems/remove-element/


1
2
3
4
5
6
7
8
9
10
class Solution {
    public int removeElement(int[] nums, int val) {
        int updateIdx = 0;
        for(int e: nums) {
            if(e == val) continue;
            nums[updateIdx++] = e;
        }
        return updateIdx;
    }
}
This post is licensed under CC BY 4.0 by the author.