Easy to understand 0ms Java Solution


  • 0
    C
    public class Solution {
        public int removeElement(int[] nums, int val) {
            int i = 0;
            for(int j = 0; j < nums.length; j++){
                if(nums[j] != val){
                    nums[i] = nums[j];
                    i++;
                }
            }
            return i;
        }
    }
    

    I used i as a counter of how many values that are different from the given val.


Log in to reply
 

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