My simple Java solution


  • 0
    V
    public int removeElement(int[] nums, int val) {
        int find = 0;
        for (int i = 0; i + find < nums.length; i++) {
            if (nums[i] == val ) {
               nums[i] = nums[nums.length-1-find];
               i--;
               find++;
            }
        }
        return nums.length - find;
    }

  • 0
    L
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.