【剑指offer】题51:数组中重复的数字
来源:互联网 发布:辐射4提取脸部数据 编辑:程序博客网 时间:2024/06/16 06:01
bool duplicate(int numbers[], int length, int* duplication) { if (numbers==NULL||length<2||duplication==NULL) { return false; } vector<int> vec(length); for (auto i = 0; i < length;++i) { if (vec[numbers[i]] != 0) { *duplication = numbers[i]; return true; } else { vec[numbers[i]] = 1; } } return false;}
bool duplicate(int numbers[], int length, int* duplication) { if (numbers==NULL||length<2||duplication==NULL) { return false; } for (auto i = 0; i < length;) { if (numbers[i] != i) { int j = numbers[i]; if (numbers[i] == numbers[j]) { *duplication = numbers[i]; return true; } else { std::swap(numbers[i], numbers[j]); } } else { i++; } } return false;}
阅读全文
0 0
- 【剑指offer】题51:数组中重复的数字
- 剑指offer--数组中重复的数字
- 《剑指offer》数组中重复的数字
- 剑指offer:数组中重复的数字
- [剑指Offer]数组中重复的数字
- 剑指offer:数组中重复的数字
- 剑指offer 数组中重复的数字
- [剑指offer]数组中重复的数字
- 剑指offer|数组中重复的数字
- 剑指offer-数组中重复的数字
- 剑指offer 数组中重复的数字
- 《剑指offer》数组中重复的数字
- 剑指offer-数组中重复的数字
- 剑指offer--数组中重复的数字
- 剑指offer--数组中重复的数字
- 剑指offer:数组中重复的数字
- 剑指offer:数组中重复的数字
- 剑指offer:数组中重复的数字
- EXCEL VBA 正则表达式
- 移动端WEB开发,click,touch,tap事件浅析
- oracle order by 处理NULL 值
- python练习2
- Session机制详解
- 【剑指offer】题51:数组中重复的数字
- DataTables上移下移排序、拖拽排序
- String.intern()解析
- iOS粒子效果模拟器—UIEffectDesigner
- C#使用OleDb操作excel数据源关于Select字段有空格问题
- objective-c跬步
- 软件工程学,第二节
- C语言桶排序实现
- 在js中如何遍历List集合,并且动态渲染下拉列表数据