循环一次,找出数组中存在的所有重复数
来源:互联网 发布:淘宝详情页模板设计 编辑:程序博客网 时间:2024/05/20 02:28
/******************主要思想******************
*哈希表
********************************************/
#include <iostream>
using namespace std;
int iArr[] = {0, 1, 2, 2, 3, 4, 5, 5};
int findMax(int arr[], int n)
{
int max = 0;
for(int i=0; i<n; i++)
{
if(max < arr[i])
{
max = arr[i];
}
}
return max;
}
void main()
{
const int iSize = sizeof(iArr)/sizeof(*iArr);
int iMax = findMax(iArr, iSize);
int* iTempArr = new int[iMax+1];
for(int i=0; i<iMax+1; i++)
{
iTempArr[i] = -1;
}
for(int i=0; i<iSize; i++)
{
int iTemp = iArr[i]%(iMax + 1);
if(iTempArr[iTemp] == -1)
{
iTempArr[iTemp] = iArr[i];
}
else
{
cout << iArr[i] << " is the first duplicate number!" << endl;
//break;
}
}
delete []iTempArr;
system("pause");
}
- 循环一次,找出数组中存在的所有重复数
- 找出数组中出现一次的数
- 找出数组中重复的数
- 找出数组中唯一重复的数
- 找出数组中重复的数
- [java]一次for循环实现查询有序数组中所有重复的元素
- 数组------找出数组中只出现一次的两个数
- 找出数组中两个只出现一次的数
- 找出数组中唯一出现一次的数
- 找出一个数组中只出现一次的数
- 找出数组中只出现一次的数(single number )
- 找出数组中两个只出现了一次的数
- 在给定数组中找出只出现一次的数
- 整数数组中找出只出现了一次的数
- 找出数组中只出现一次的两个数
- 找出一个数组中只出现一次的两个数
- 找出一个数组中没重复出现过的数
- 找出数组中不重复的数并显示出来
- WinX教程之我的实战(一)
- 使用XDoclet生成代码
- BOM问题
- 做个清新自信的男人
- c#自定义二分查找法
- 循环一次,找出数组中存在的所有重复数
- OpenGL显示中文
- struts+hibernate项目debug总结
- 权限系统设计
- 编程之道
- 关于list-(5) 单向list反转
- 史上最强的跟帖
- 右键菜单的创建
- Intel Core: A Next-Generation Microarchitecture (原英文版本来自于INTEL)