Find First and Last Position of Element in Sorted
Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. [#34]
Your algorithm's runtime complexity must be in the order of O(log n).
If the target is not found 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]
Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array. [#35]
Example: Input: [1,3,5,6], 5 Output: 2 Input: [1,3,5,6], 2 Output: 1 Input: [1,3,5,6], 7 Output: 4 Input: [1,3,5,6], 0 Output: 0
相关单词
position
英 [pəˈzɪʃn] 美 [pəˈzɪʃn]
n.位置;地方;恰当位置;正确位置;(坐、立的)姿态,姿势;放置方式
vt.安装;安置;使处于
词根-posit- 放,放置
后缀-ion 表名词
ascend
英 [əˈsend] 美 [əˈsend]
v.上升;升高;登高
前缀a- 加强
词根-scend- 爬,攀
insert
英 [ɪnˈsɜːt , ˈɪnsɜːt] 美 [ɪnˈsɜːrt , ˈɪnsɜːrt]
vt.插入;嵌入;(在文章中)添加,加插
n.(书报的)插页,广告附加页;插入物;添加物
前缀in- 进入
词根-sert- 加入