File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ # Constraints
3+
4+ 1 <= nums.length <= 10^5
5+ -10^9 <= nums[i] <= 10^9
6+
7+ # Time Complexity: O(n)
8+
9+ ๋ฐฐ์ด ๋ด ์์๋ฅผ ์ํํ๋ฉฐ ๊ฐ ์์๋ณ๋ก ๋ฑ์ฅํ์๋ฅผ ๊ธฐ๋ก
10+ -> ๋ฌด์จ ์์๊ฐ ๋ค์ด์๋์ง ๋ชจ๋ฅด๋ฏ๋ก, defaultdict๊ฐ ์ข์๋ณด์
11+ -> ๋ฑ์ฅ ํ์ ๊ฐ์ด 2 ์ด์์ธ ๊ฒฝ์ฐ ๋ฐฐ์ด ์ํ ๋ฉ์ถ๊ธฐ
12+
13+ # Space Complexity: O(n)
14+
15+ ์ต๋ ๋ฐฐ์ด ์์ ๊ฐ์๋งํผ key-value ์ง๋๋ ์ฌ์ ํ์ฉ
16+ """
17+
18+ from collections import defaultdict
19+ class Solution :
20+ def containsDuplicate (self , nums : List [int ]) -> bool :
21+ count_dict = defaultdict (int )
22+
23+ for n in nums :
24+ if count_dict [n ] + 1 >= 2 :
25+ return True
26+
27+ else :
28+ count_dict [n ] += 1
29+
30+ return False
You canโt perform that action at this time.
0 commit comments