This C++ ok and beat 74.32% with 40ms


  • 0
    L

    This sulotion delete the replicates and match the length to the original lenght.

    The idea is to detectt the length change after the unique-earas operation.

    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            int len_o = nums.size();
            sort(nums.begin(),nums.end());
            nums.erase(unique(nums.begin(),nums.end()),nums.end());
            return len_o-nums.size();
            
        }
    };  // 2016 06 12 凌晨

Log in to reply
 

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