12. Any Repeat Visitor
A museum scans a numbered pass at the entrance every time someone walks in. Each pass is meant to be used only once per day, so if the same pass number is scanned twice, somebody has shared their pass.
Write a method hasDuplicate that takes the array nums of scanned pass numbers and returns true if any pass number appears at least twice, and false if every scanned number is different.
Example 1
- Input:
- nums = [101,205,330,101]
- Output:
- true
- Explanation:
Pass 101 was scanned twice, so the answer is true.
Example 2
- Input:
- nums = [1,2,3,4]
- Output:
- false
- Explanation:
Every pass number is different, so the answer is false.
Constraints
1 ≤ nums.length ≤ 1000
-109 ≤ nums[i] ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(n)
- Space
- O(n)