首页 > 编程语言 > 详细

剑指OFFER 数组中重复的数字

时间:2020-01-13 18:42:15      阅读:78      评论:0      收藏:0      [点我收藏+]

剑指OFFER 数组中重复的数字

使用哈希表来完成

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
    
    map<int,int> m;
    bool duplicate(int num[], int length, int* duplication) {
        for(int i=0;i<length;i++)
        {
            m[num[i]]++;
            if(m[num[i]] > 1)
            {
                (*duplication) = num[i];
                return true;
            }
        }
        return false;
    }
};

剑指OFFER 数组中重复的数字

原文:https://www.cnblogs.com/virgildevil/p/12188398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!