Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int removeElement(int[] nums, int val) {
- int i = 0;
- int n = nums.length;
- while (i < n) {
- if (nums[i] == val) {
- nums[i] = nums[n - 1];
- // reduce array size by one
- n--;
- } else {
- i++;
- }
- }
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement