704. 二分查找
问题704 二分查找 ☆☆☆☆☆ https://leetcode-cn.com/problems/binary-search/ public int search(int[] nums, int target) { assert nums.length > 0; int left = 0, right = nums.length - 1; while (left ...
问题704 二分查找 ☆☆☆☆☆ https://leetcode-cn.com/problems/binary-search/ public int search(int[] nums, int target) { assert nums.length > 0; int left = 0, right = nums.length - 1; while (left ...
问题4 寻找两个正序数组的中位数 ★★★☆☆ https://leetcode.cn/problems/median-of-two-sorted-arrays/ 这个题目本身并不难理解,给定两个有序数组,求这两个有序数组一起构成的集合的中位数。如果是给定一个有序数组,我们很容易得到这个有序数组的中位数,只需要根据数组长度计算中位数的下标,然后直接读取对应的数据即可。那么显然,这个题目我们可...
问题35 搜索插入位置 ★☆☆☆☆ https://leetcode-cn.com/problems/search-insert-position/ 这个题目比较简单了,属于二分查找的微小变种,在二分查找的基础上增加一个插入位置下标的计算而已。稍微想一下两个连续元素的二分查找过程就可以确认最后返回right+1即可。 public int searchInsert(int[] nums...
问题34 在排序数组中查找元素的第一个和最后一个位置 ★☆☆☆☆ https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 这个题目属于二分查找的变种,直觉上就是连续二分查找。看了官方题解,我觉得还不如这种处理容易理解。 public int[] searchRa...
问题33 搜索旋转排序数组 ★★☆☆☆ https://leetcode-cn.com/problems/search-in-rotated-sorted-array/ 这个题目是经典的二分查找的变种,而题目要求又是O(log(N))的时间复杂度,那么直觉上应该还是从二分查找入手。对于二分查找的题目,重点就是二分后如何舍弃一半。经典的二分查找算法中,由于单调递增性,通过比较mid元素和ta...
问题278 第一个错误的版本 ★☆☆☆☆ https://leetcode-cn.com/problems/first-bad-version/ 这个题目是二分查找的变种,相比问题35稍微难一点点,在二分查找的基础上稍作修改即可。值得注意的地方是,这里二分查找的循环条件是low < high,而不是low <= high,注意体会为什么是这样。其实也很好理解,把握住循环不变量是...
问题162 寻找峰值 ★☆☆☆☆ https://leetcode-cn.com/problems/find-peak-element/ 这个题目的关键是二分后如何舍弃某一半: 当前二分点恰好是一个peek点,那么直接返回即可 当前二分点不是peek点,那么当前二分点可能处于三种状态:小于左邻大于右邻,大于左邻小于右邻,小于左邻小于右邻。我们只需要向较大的邻点靠近就可以了,即舍弃...
问题153 寻找旋转排序数组中的最小值 ★★☆☆☆ https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/ 这个题目和问题33几乎一样,问题33是查找特定值,问题153是查找最小值,都是基于rotation破坏有序性做文章。在问题33的经验之上,我们可以很容易判断mid节点是在左侧上升段还是右侧上升段。不...
Deployment is a combination of two interrelated concepts: process and architecture. The deployment process consists of the steps that must be performed by people, developers and operations, in orde...
Security An application developer is primarily responsible for implementing four different aspects of security: authentication, verifying the identity of the application or human that’s attempti...