题解 | #二分查找-I#

二分查找-I

https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b

给自己看
class Solution:
    def search(self , nums: List[int], target: int) -> int:
        
        if target in nums:
            left = 0
            right = len(nums)-1
            while left!=right:
                if nums[int((left+right)/2)]>target:
                    right = int((left+right)/2)-1
                elif nums[int((left+right)/2)]==target:
                    left = int((left+right)/2)
                    break
                else:
                    left = int((left+right)/2)+1
            return left
        else:
            return -1


#二分查找#
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 13:35
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务