leetcode 34[medium]---Search for a Range
难度:medium
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.
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]
.
For example,
Given [5, 7, 7, 8, 8, 10]
and target value 8,
return [3, 4]
.
思路:有点搞不懂leetcode的难度分类,明明有些easy级别的题都要难出此题很多。当然也许是自己的python知识结构还太不完善的原因。
给定一个已经sort过的array,找出给定target所在的范围,如果array中没有与target值相同的element则return[-1,-1]. 如果array中只有一个target的element,return[i,i].