C++/代码:

数组中重复的数字

http://www.nowcoder.com/questionTerminal/623a5ac0ea5b4e5f95552655361ae0a8

C++/代码

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) {
        if(numbers == NULL || length==0) return false;
        for(int i = 0;i < length;i ++){
            if(numbers[i] <= 0 || numbers[i] >= length) return false;
        }
        for(int i = 0;i < length;i ++){
            while(numbers[i] != i && numbers[i] != numbers[numbers[i]]) swap(numbers[i],numbers[numbers[i]]);
            if(numbers[i] != i && numbers[i] == numbers[numbers[i]]) {
                *duplication = numbers[i];
                break;
            }
        }
        return true;
    }
};
全部评论

相关推荐

大猪蹄子哥:1-谁教你这么写教育经历的……咱都这个学历了,很多公司要看本科、硕士,Gap Year的,你啪就给一个上大26届硕士,没了。 2-那堆奖学金揉成一行放最后得了,放前面显得你没技术自信,还是那句话,对于咱这个学历直接上重点,你这上半段看起来像个大专(无恶意 3-专业技能最好点出来细化方向,你熟悉的以太网是UDP还是TCP,是千兆还是万兆等等,多种信号处理……那你倒是说两个啊,后面空着干嘛,会的干嘛不讲 4-项目经历废话太多,描述不专业(怎么还有我,我们这种词),没有数据支撑(是婴儿还是巨人看不出来)。最后如果这些是真的XX项目、比赛,最好点出来,不然更显得像自学着玩的,或者说抄的(经典复现等于我做过 5-个人总结在咱这个分段没用
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务