Share 0ms java solution


  • 0
    L
    public class Solution {
    public int removeElement(int[] nums, int val) {
        if(nums.length==0) return 0;
        int start=0;
        int end=nums.length-1;
        int temp;
        while(start<=end){
            if(nums[start]==val){
                temp=nums[start];
                nums[start]=nums[end];
                nums[end]=temp;
                end--;
            }
            else {
                start++;
            }
        }
        return end+1;
    }
    

    }


Log in to reply
 

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