My solution by c++ 97.55%


  • -11
    L
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            int tem[1000000];
            memset(tem,0,sizeof(tem));
            for(int i=0;i<nums.size();++i)
            {
                if(tem[nums[i]]>0)
                return true;
                else ++tem[nums[i]];
            }
            return false;
        }
    };

  • 0
    N

    It only works when the numbers in the original array are all equal or less than 1000000; but it indeed works fast.


  • 0
    L

    Yes, you are right.


  • 0
    B

    if some elements in the array are negative, this solution will not work yet.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.