腾讯面试题 找重复的数

给定一个数组, 有一个数是重复的,找到这个数,要求时间复杂度是O(N),空间复杂度不能超过O(N)

很简单,自己当时老往排序上面想了..

#include 
#include 
#include 

using namespace std;

int main()
{
    int arr[] = {1, 2, 3, 5, 5, 6, 7, 8};

    int len = sizeof(arr)/sizeof(*arr);

    vector v;

    for(int i = 0; i < len; i++)
    {
        vector::iterator it = find(v.begin(), v.end(), arr[i]);

        if(it != v.end())
        {
            cout<<"the same number is "<

 

转载于:https://www.cnblogs.com/xshang/p/7247870.html

你可能感兴趣的:(腾讯面试题 找重复的数)