标签:
题目: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.
查找一个数组中是否含有重复元素,可以利用哈希实现
代码:
class Solution { public: bool containsDuplicate(std::vector<int>& nums) { std::set<int> s; for (int i = 0; i < nums.size(); ++i) { s.insert(nums[i]); } return s.size() != nums.size(); } };
[LeetCode217]Contains Duplicate
标签:
原文地址:http://www.cnblogs.com/zhangbaochong/p/5140660.html