Simple and easy Java solution


  • 2
    Y
    public class Solution {
        public int removeElement(int[] nums, int val) {
            int l = -1;
            for(int i = 0;i < nums.length;i++)
                if(nums[i] != val)
                    nums[++l] = nums[i];
            return l + 1;
        }
    }

Log in to reply
 

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