LeetCode 217 Contains Duplicate
LeetCode 217 Contains Duplicate
一种C++实现,先排序,再比较相邻值是否相等:
class Solution { public: bool containsDuplicate(vector<int>& nums) { std::sort(nums.begin(),nums.end()); for (int i = 1; i < nums.size(); i++) { if (nums[i-1] == nums[i]) return true; } return false; } };
用时40ms