代码随想录算法训练营第一天| 704.二分查找、27.移除元素、977.有序数组的平方
数组 PART 1704. 二分查找leetcode.704 题目链接 二分查找文字讲解 二分查找视频讲解 解题思路: 首先要确认包含数据的区间的类型(闭区间,闭开区间),并将这个区间类型作为循环不变量,因为寻找的数字一定包含在这个区间内是不变的,以这个区间类型合法区间作为边界条件就不会出错。并且在计算middle的时候有一个注意事项是当两个整数相加的时候为了防止溢出可以采用 left + (right - left)/ 2 或者 left + ((right - left) >> 1)的形式。 二分查找适用的题目类型:有序数组且无重复元素 时间复杂度:O(logn) 空间复杂度:O(1) 合法区间为闭区间的代码实现: 123456789101112131415161718192021222324252627282930#include<iostrem>#include<vector>using namespace std;int main(){ vector<int> nums =...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment