Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
1 2 3 4 5 6 7 8 9 10 |
class Solution { public: bool containsDuplicate(vector<int>& nums) { set<int> m; for(int i = 0; i < nums.size(); i++) { m.insert(nums[i]); } return nums.size() != m.size(); } }; |
❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼