Problem
LeetCode 217: Contains Duplicate
Solution
| |
Explaination
We leverage nature of python sets, which gives O(1) for membership check and adding new member, in worst case scenario it is O(n).
References
Also see
- Concatenation of Array
- Valid Anagram
- Two Sum
- Longest Common Prefix
- Group Anagrams
- Remove Element
- Majority Element
- Design HashSet
- Design HashMap
- Sort an Array
- Sort Colors
- Top K Frequent Elements
- Encode and Decode Strings
- Range Sum Query 2D Immutable
- Product of Array Except Self
- Valid Sudoku
- Longest Consecutive Sequence
- Best Time to Buy And Sell Stock II
- Majority Element II
- Subarray Sum Equals K
- First Missing Positive