数组中重复的数字python3(剑指Offer03 )

#剑指 Offer 03. 数组中重复的数字

找出数组中重复的数字

例子:

输入:
[2, 3, 1, 0, 2, 5, 3]
输出:2 或 3 

不考虑太多限制的话:

class Solution:
    def findRepeatNumber(self, nums: List[int]) -> int:
        nums = sorted(nums)
        for i in range(1, len(nums)):
            if nums[i] == nums[i - 1]:
                return nums[i-1]

猜你喜欢

转载自blog.csdn.net/ziqingnian/article/details/121877989