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
- 데이콘
- dacon
- SW Expert Academy
- hackerrank
- 자연어처리
- 코로나19
- 프로그래머스
- 프로그래머스 파이썬
- 백준
- 편스토랑
- AI 경진대회
- programmers
- Kaggle
- 더현대서울 맛집
- PYTHON
- Docker
- 편스토랑 우승상품
- 캐치카페
- ChatGPT
- ubuntu
- 파이썬
- gs25
- Real or Not? NLP with Disaster Tweets
- Git
- Baekjoon
- github
- 우분투
- 맥북
- leetcode
- 금융문자분석경진대회
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 287. Find the Duplicate Number (Python) 본문
728x90
반응형
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
- You must not modify the array (assume the array is read only).
- You must use only constant, O(1) extra space.
- Your runtime complexity should be less than O(n2).
- There is only one duplicate number in the array, but it could be repeated more than once.
Solution
from collections import Counter
class Solution:
def findDuplicate(self, nums: List[int]) -> int:
answer = 0
cnt = Counter(nums)
for key, val in cnt.items():
if val != 1:
answer = key
break
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 605. Can Place Flowers (Python) (0) | 2020.06.30 |
---|---|
[BaekJoon] 11576번 : Base Conversion (Python) (2) | 2020.06.29 |
[BaekJoon] 11005번 : 진법 변환 2 (Python) (0) | 2020.06.28 |
[BaekJoon] 11055번 : 가장 큰 증가 부분 수열 (Python) (0) | 2020.06.28 |
[BaekJoon] 11054번 : 가장 긴 바이토닉 부분 수열 (Python) (0) | 2020.06.28 |
Comments