0ms JAVA solution


  • 1
    V

    public class Solution {

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

    }


Log in to reply
 

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