数组中重复的数字
2016-04-27 21:33
393 查看
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) { bool res=false; if(length==0) return res; vector<int> num(length,0); for(int i=0;i<length;i++) { if(numbers[i]>=0&&numbers[i]<=length-1) { num[numbers[i]]++; if(num[numbers[i]]>1) { *duplication=numbers[i]; res=true; } } else return false; } return res; } };
相关文章推荐
- Python分析网页神器pyquery
- vi/vim编辑器必知必会
- poj 2632Crashing Robots
- HDU2053
- CodeForces - 237A Free Cash (水)
- [POJ 2155] Matrix (高维树状数组)
- 安装Redis完整过程
- 剑指offer(42):数组中只出现1次的数字
- 受限玻尔兹曼机(Restricted Boltzmann Machine,RBM)
- 回文字符串
- 解决spring mvc中ajax传值所报的错误400 415
- leetcode-20. Valid Parentheses
- 【Linux】Red Hat Linux 图形界面切换命令界面
- Mybatis最入门---分页查询(拦截器分页原理及实现)
- python中文编码坑
- Power Designer使用方法
- UVA 10245 The Closest Pair Problem【分治】
- JAVA——如何停止线程呢?(interrupt)
- 杭电2006
- 如何避免大量重复URL被百度收录