Skip to main content

🟢 剑指 Offer 53 - II. 0~n-1中缺失的数字

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def missingNumber(self, nums: List[int]) -> int:        l, r = 0, len(nums)-1        while l < r:            mid = (l+r)//2            if nums[r] == r:                return nums[r]+1            if nums[mid] == mid+1:                r = mid            else:                l = mid+1        return l+1 if nums[l] == l else l