Last active
July 18, 2017 02:35
-
-
Save BiruLyu/17547405dd4627c092b808f6ae1d5f2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int removeElement(int[] nums, int val) { | |
if (nums.length == 0 || nums == null) return 0; | |
Arrays.sort(nums); | |
int count = 0; | |
for (int i = 0; i < nums.length; i++){ | |
if (nums[i] < val) { | |
continue; | |
} else if (nums[i] == val) { | |
count++; | |
} else { | |
nums[i - count] = nums[i]; | |
} | |
} | |
return nums.length - count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment