268. 缺失数字

我的答案:(没满足说明吧ToT)

 

class Solution(object):
    def missingNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for i in range(len(nums)+1):
            if i not in nums:
                return i

268. 缺失数字

正确答案:Accept(当然是别人想到的)https://blog.csdn.net/qq_34364995/article/details/80699747

268. 缺失数字

(被折服。。)

268. 缺失数字

 

class Solution(object):
    def missingNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums.sort()
        i=0
        # 0,1,2
        for value in nums:
            if i-value != 0:
                return i
            else:
                i += 1
        return i


def main():
    nums = [0]
    myResult = Solution()
    print(myResult.missingNumber(nums))

if __name__ == '__main__':
    main()

 

相关文章:

  • 2022-12-23
  • 2021-05-15
  • 2021-11-10
  • 2022-12-23
  • 2021-09-02
  • 2021-07-13
  • 2022-12-23
  • 2022-03-02
猜你喜欢
  • 2021-06-01
  • 2021-10-01
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
相关资源
相似解决方案