美文网首页
数组中重复的数字

数组中重复的数字

作者: UAV | 来源:发表于2020-06-22 06:44 被阅读0次

题目描述

在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。请找出数组中任意一个重复的数字。 例如,如果输入长度为7的数组{2,3,1,0,2,5,3},那么对应的输出是第一个重复的数字2。

class Solution {
public:
    // Parameters:
    //        numbers:     an array of integers
    //        length:      the length of array numbers
    //        duplication: (Output) the duplicated number in the array number
    // Return value:       true if the input is valid, and there are some duplications in the array number
    //                     otherwise false
    bool duplicate(int numbers[], int length, int* duplication) {
        for (int i = 0; i < length; i++)
        {
            int tmp = numbers[i];
            for (int j = i+1; j < length; j++)
            {
                if (tmp==numbers[j]) {
                    *duplication = tmp;
                    return true;
                }
            }
        }
        return false;
    }
};

相关文章

  • 剑指offer题集

    [3] 数组中重复的数字 题目一:找出数组中重复的数字 Description 在一个长度为n的数组里的所有数字都...

  • LeetCode 每日一题 [38] 数组中重复的数字

    LeetCode 数组中重复的数字 [简单] 找出数组中重复的数字。在一个长度为 n 的数组 nums 里的所有数...

  • 剑指offer4J【C2 P3】找出数组中重复数字

    题目 找出数组中重复的数字数组中数字都在0~n之间,其中有些数字是重复的,但不知道谁重复,可能有1到多个重复的数字...

  • 面试题03. 数组中重复的数字

    数组中重复的数字 题目描述 找出数组中重复的数字。 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-...

  • 数组中重复的数字

    题目一:找出数组中重复的数字 在一个长度为 n 的数组里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复...

  • 剑指offer学习笔记:8.1 数组

    面试题51:数组中重复的数字在一个长度为n的数组中,所有数字都在0到n-1的范围内。数组中的某些数字是重复的,但是...

  • 数组中重复的数字

    题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重...

  • 数组中重复的数字

    数组中重复的数字 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个...

  • 数组中重复的数字

    题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重...

  • 数组中重复的数字

    在一个长度为n的数组里的所有数字都在0到n-1的范围内。 数组中某些数字是重复的,但不知道有几个数字是重复的。也不...

网友评论

      本文标题:数组中重复的数字

      本文链接:https://www.haomeiwen.com/subject/puvtfktx.html