1. 程式人生 > >leetcode 217. Contains Duplicate

leetcode 217. Contains Duplicate

nbsp i++ and div ++ ets cto ont tco

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

這個題有很多種做法:https://leetcode.com/problems/contains-duplicate/discuss/61110/C++-solutions-(sorting-maps-and-sets).

還有Contains Duplicate II Contains Duplicate III

leetcode 217. Contains Duplicate