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



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |