duplicate
来源:互联网 发布:淘口令没有在淘宝弹出 编辑:程序博客网 时间:2024/06/05 19:48
#include <string>#include <iostream>#include <vector>using namespace std;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 find=false; for(int i=0;i<length;i++) { if(numbers[i]<0||numbers[i]>length-1) return false; while(i!=numbers[i]) { if(numbers[numbers[i]]==numbers[i]) { find=true; (*duplication)=numbers[i]; break; } int temp=numbers[numbers[i]]; numbers[numbers[i]]=numbers[i]; numbers[i]=temp; } if(find) break; } if(find) { for(int i=0;i<length;i++) if(numbers[i]<0||numbers[i]>length-1) return false; return true; } return false; }};
1 0
- duplicate
- Duplicate.
- Duplicate Database
- sql duplicate
- Duplicate Emails
- Duplicate Emails
- Contains Duplicate
- Contains Duplicate
- Duplicate Emails
- Contains Duplicate
- Leetcode_217_Contains Duplicate
- Contains Duplicate
- Contains Duplicate
- Contains Duplicate
- Contains Duplicate
- leetcode_Contains Duplicate
- Contains Duplicate
- Contains Duplicate
- java自学视频网站
- 有关AndroidStudio使用的那些技巧
- 关于网页公共部分的引用
- Java源码分析之HashSet
- 如何查看eclipse的版本
- duplicate
- C快速排序玩法
- 重读java编程思想--一切都是对象(1)
- Servlet中的重要对象——ServletConfig对象
- Canvas对图片进行像素类型坐标化
- 修改PyCharm的设置让新建python文件指定编码为utf-8
- h5第一课
- 求一个整数的位数,输出它,以及逆序
- hdu 1002大数加法