40ms c++ solution(cry cry cry....)


  • 2
    S
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            int len = nums.size();
            if(len == 1)  return false;
            sort(nums.begin(),nums.end());
            for(int i = 0;i < len-1; i++)
                if(nums[i] == nums[i+1])   return true;
            return false;
        }
    };

  • 0
    D

    Both sorting,Why C++ needs 40ms but Java only needs 6ms?
    Why Java is faster than C++?


  • 0
    D
    This post is deleted!

Log in to reply
 

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