In-place 2-line C++ solution, w/ <algorithm>


  • 3
    A
    #include <algorithm>
    class Solution {
    public:
        bool containsDuplicate(vector<int>& nums) {
            std::sort(nums.begin(), nums.end());
            return std::adjacent_find(nums.begin(), nums.end()) != nums.end();
        }
    };

Log in to reply
 

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