Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 455 Bytes

README.md

File metadata and controls

27 lines (21 loc) · 455 Bytes

Remove Element

Solution 1

Two Pointers

class Solution {
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int slow = 0;
        int fast = 0;

        for (; fast < nums.length; fast++) {
            if (nums[fast] != val) {
                nums[slow] = nums[fast];
                slow++;
            }
        }

        return slow;
    }
}