Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md
solve.cpp

README.md

Contains Duplicate

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.

Solution

直接使用hashtable即可

bool containsDuplicate(vector<int> &nums) {
	unordered_set<int> set;
	for (int i : nums) {
		if (set.find(i) != set.end())
			return true;
		else
			set.insert(i);
	}
	return false;
}

扩展

You can’t perform that action at this time.