class Solution {
public int search(int[] nums, int target) {
int left = 0;
int right = nums.length -1;
while (left <= right) {
int mid = (right + left) / 2;
if (nums[mid] < target) {
left = mid + 1;
} else if (nums[mid] > target) {
right = mid - 1;
} else {
return mid;
}
}
return -1;
}
}
class Solution {
public int removeElement(int[] nums, int val) {
// 快指针:寻找新数组的元素 ,新数组就是不含有目标元素的数组
// 慢指针:指向更新 新数组下标的位置
int slowPointer = 0;
for (int fastPointer = 0; fastPointer < nums.length; fastPointer++){
if (nums[fastPointer] != val) {
nums[slowPointer] = nums[fastPointer];
slowPointer++;
}
}
return slowPointer;
}
}