二分查找
力扣题目#704704. 二分查找 - 力扣(LeetCode)https://leetcode.cn/problems/binary-search/
注意最左、右端值的位置,以及何时用 middle-1,何时用 middle
左闭右闭
左闭右开
移除元素
力扣题目#2727. 移除元素 - 力扣(LeetCode)https://leetcode.cn/problems/remove-element/description/
双指针的做法
注意:当然在java里面是没有指针的说法,只是说一句而已
class Solution {
public int removeElement(int[] nums, int val) {
int length = nums.length;
int fast;
int slow = 0;
for(fast = 0; fast < length; fast++){
if(nums[fast] != val){
nums[slow] = nums[fast];
slow++; //当然这里可以与上一行换成nums[slow++],先用后加
}
}
return slow;
}
}