中级农民
- 积分
- 115
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2019-12-7
- 最后登录
- 1970-1-1
|
06.21 打卡第十天 刷题第十天
第十天未被加米了,楼主救我!
Leetcode:
724. Find Pivot Index
Mindset: Prefix sum
find the sum first then linear scan from leftMost to rightMost again
compare with two sums and get a conclusion.
561. Array Partition I
Mindset: sort it first then we can sum up all the even(index) number;
Binary Search
3.Classical Binary Search
Use two pointers
always maintain a size >= 2 searching range
then post-processing
4.First Occurance
if (array[left] <= target) {
left = mid;
}
the left pointer does not jump through mid
Right pointer jump one for the right;
5.Last Occurance
similarliy:
if (array[right] >= target) {
right = mid;
}
the right pointer does not jump through mid
left pointer jump one for the left;
6. Find the Floor/Ceiling in a sorted array
watch out for the corner case, which is all the element is larger than target, so can not find Floor, return -1;
watch out for the corner case, which is all the element is smaller than target, so can not find Ceiling, return -1;
7.Search in sorted unknown sized array
Handle the right side of the case, watch out for the mid or right would point to null; |
|