all is taolu


  • 1
    C
        public int removeElement(int[] nums, int val) {
            int j = 0;
    	for(int i = 0;i<nums.length;i++) {
    		if(nums[i] != val) {
    			swap(nums,i,j);
    			j++;
    		}
    	}
    	return j;
        }
        public static void swap(int[] nums,int i, int j) {
    	int temp = nums[i];
    	nums[i] = nums[j];
    	nums[j] = temp;
        }

  • 0
    M

    6666666666666666


Log in to reply
 

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