LeetCode brush title
leetcode Code Complete: https://github.com/czy36mengfei/leetcode
First, the array
1, dichotomy
2020.02.10
Nums Given an array of integers arranged in ascending order, according to the target and one target value. Identify a given target start and end positions in the array.
Your time complexity of the algorithm must be O (log n) level.
If the target is not present in the array, return [-1, -1].
Example 1:
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Example 2:
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1, -1]
Source: stay button (LeetCode)
link: https: //leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array
2020.02.11
Array - dichotomy: leetcode 035 Given a sorted array and a target, find the object in the array, and returns its index. If the target is not present in the array, it will be returned in sequence inserted position.
You may assume that no duplicate elements in the array.
Example 1:
Input: [1,3,5,6], output 5: 2 Example 2:
Input: [1,3,5,6], output 2: 1 Example 3:
Input: [1,3,5,6], the output 7: 4 Example 4:
Input: [1,3,5,6], output 0: 0
Source: stay button (LeetCode) link: https: //leetcode-cn.com/problems/search-insert-position