public int removeElement(int[] nums, int val) {

if(nums == null || nums.length == 0) return 0;

int left = 0;

int right = nums.length-1;

while(left <= right && nums[right]==val) { //for "=" see the example: {1}, 1

right--;

}

while(left <= right) {

if(nums[left]==val) {

int temp = nums[left];

nums[left] = nums[right];

nums[right] = temp;

while(left < right && nums[right]==val) {

right--;

}

}

left++;

}

return right+1;

}