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 |
Tags
- leetcode
- 프로그래머스
- 캐치카페
- 금융문자분석경진대회
- programmers
- 편스토랑
- Real or Not? NLP with Disaster Tweets
- 백준
- Baekjoon
- ChatGPT
- Git
- ubuntu
- Docker
- 편스토랑 우승상품
- 더현대서울 맛집
- 파이썬
- 데이콘
- 자연어처리
- SW Expert Academy
- hackerrank
- AI 경진대회
- 우분투
- 코로나19
- gs25
- PYTHON
- Kaggle
- dacon
- 프로그래머스 파이썬
- 맥북
- github
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