March 07, 2022

27. Remove Element

27. Remove Element

class Solution {
    public int removeElement(int[] nums, int val) {
        int end = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[end++] = nums[i];
            }
        }
        return end;
    }
}
comments powered by Disqus