704. 二分查找
int search(int* nums, int numsSize, int target) {
int left = 0, right = numsSize, mid;
while (left < right) {
mid = left + (right -left) / 2;
if (nums[mid] < target) {
left = mid + 1;
} else if (nums[mid] > target) {
right = mid;
} else {
return mid;
}
}
return -1;
}
27. 移除元素
int removeElement(int* nums, int numsSize, int val) {
int slow = 0, fast = 0;
for (fast = 0; fast < numsSize; fast++) {
if (nums[fast] != val) {
nums[slow++] = nums[fast];
}
}
return slow;
}