您当前的位置: 首页 >  leetcode

孑渡

暂无认证

  • 1浏览

    0关注

    178博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Leetcode】剑指Offer 03:数组中重复的数字

孑渡 发布时间:2022-08-07 18:25:01 ,浏览量:1

找出数组中重复的数字。 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

AC代码
class Solution:
    def findRepeatNumber(self, nums: List[int]) -> int:
        easylist = [0 for _ in range(len(nums))]
        for i in nums:
            easylist[i] += 1
            if easylist[i] >= 2:
                return i
            
妙解
class Solution {
public:
    int findRepeatNumber(vector& nums) {
        int n = nums.size();
        for(int i = 0; i             
关注
打赏
1663211900
查看更多评论
0.0666s