[LeetCode]Remove Element
public class Solution { public int removeElement(int[] nums, int val) { if (nums.length == 0) { return 0; } int left = 0; int right = nums.length - 1; while (left < right) { if (nums[left] != val || nums[right] == val) { if (nums[left] != val) { left ++; } if (nums[right] == val) { right --; } } else { int tmp = nums[left]; nums[left] = nums[right]; nums[right] = tmp; } } return nums[left] == val ? left : left + 1; } }