My Simple Java Solution


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

Log in to reply
 

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