A 36ms Simple C++ Solution


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

Log in to reply
 

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