[LeetCode] Contains Duplicate
1. ๋ฌธ์ : Link
2. ํ์ด
๋จ์ํ ๋ฆฌ์คํธ ํ์ธ์ผ๋ก ํ๋ฉด ์๊ฐ์ด๊ณผ๊ฐ ๋์์ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ํ์๋ค.
3. ์ฝ๋
sol1) ํด์ฌ
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
tmp = {}
for n in nums:
if n in tmp:
return True
else:
tmp[n] = 1
return False
sol2) ๋ฆฌ์คํธ ๊ธธ์ด
class Solution:
def containsDuplicate_2(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (์๋ฐ java) (0) | 2022.11.24 |
---|---|
[LeetCode] Product of Array Expect Self (0) | 2022.07.09 |
[LeetCode] Best Time to Buy and Sell (0) | 2022.07.03 |
[LeetCode] Two Sum (0) | 2022.06.30 |
[BOJ 1789] ์๋ค์ ํฉ (0) | 2022.06.26 |
์ต๊ทผ๋๊ธ