剑指offer刷题笔记||03.数组中重复的数字(python) 题目描述: 解题思路 因为题目只要求输出其中的一个重复数,所以可以对其经进行排序,然后用第一个数对后面进行比较,找到重复值便返回即可。 我的代码: class Solution(object): def findRepeatNumber(self, nums): """ :type nums: List[int] :rtype: int """ nums.sort() pre = nums[0] for i in nums[1:]: if pre == i: return pre pre = i 提交结果: