Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Baekjoon
- dacon
- 편스토랑
- 데이콘
- SW Expert Academy
- 우분투
- Kaggle
- Git
- 금융문자분석경진대회
- leetcode
- 맥북
- 편스토랑 우승상품
- Real or Not? NLP with Disaster Tweets
- 자연어처리
- programmers
- 코로나19
- AI 경진대회
- 파이썬
- 프로그래머스
- hackerrank
- 더현대서울 맛집
- ubuntu
- 백준
- github
- Docker
- 캐치카페
- PYTHON
- gs25
- ChatGPT
- 프로그래머스 파이썬
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 217. Contains Duplicate (Python) 본문
728x90
반응형
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
Input: [1,2,3,1]
Output: true
Example 2:
Input: [1,2,3,4]
Output: false
Example 3:
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true
Solution
from collections import Counter
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
answer = False
cnt = [c[1] for c in list(Counter(nums).items()) if c[1] > 1]
if len(cnt) > 0:
answer = True
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 482. License Key Formatting (Python) (0) | 2020.10.31 |
---|---|
[leetCode] 219. Contains Duplicate II (Python) (0) | 2020.10.28 |
[leetCode] 179. Largest Number (Python) (0) | 2020.10.25 |
[leetCode] 27. Remove Element (Python) (0) | 2020.10.24 |
[leetCode] 216. Combination Sum III (Python) (0) | 2020.10.23 |
Comments