Review Note
Last Update: 07/03/2024 02:06 AM
Current Deck: LeetCode
PublishedCurrently Published Content
Front
217. Contains Duplicate
- Given an integer array
nums
, returntrue
if any value appears at least twice in the array, and returnfalse
if every element is distinct.
Back
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
seen = set()
for n in nums:
if n in seen:
return True
seen.add(n)
return False
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> s;
for (int n : nums) {
if (s.count(n))
return true;
s.insert(n);
}
return false;
}
};
Current Tags:
Pending Suggestions
No pending suggestions for this note.