0
点赞
收藏
分享

微信扫一扫

Leedcode升序序列查找元素位置

zmhc 2022-01-26 阅读 34

一拿到这题,想法很简单,要么二分要么利用index

index无脑解法:(效率还挺高)

class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        if target not in nums:return [-1,-1]
        a=nums.index(target)
        b=nums[::-1].index(target)
        return [a,len(nums)-1-b]
        

 

 二分法:

暂时没有想出来.....

举报

相关推荐

0 条评论