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
- 편스토랑 우승상품
- AI 경진대회
- 프로그래머스
- Real or Not? NLP with Disaster Tweets
- gs25
- Baekjoon
- 금융문자분석경진대회
- 맥북
- 편스토랑
- 파이썬
- SW Expert Academy
- Docker
- ChatGPT
- 백준
- ubuntu
- github
- Git
- 데이콘
- 더현대서울 맛집
- dacon
- 캐치카페
- 우분투
- PYTHON
- Kaggle
- programmers
- 자연어처리
- 코로나19
- 프로그래머스 파이썬
- hackerrank
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 645. Set Mismatch (Python) 본문
728x90
반응형
The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number.
Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array.
Example 1:
Input: nums = [1,2,2,4]
Output: [2,3]
Note:
- The given array size will in the range [2, 10000].
- The given array's numbers won't have any order.
Solution
from collections import Counter
class Solution:
def findErrorNums(self, nums: List[int]) -> List[int]:
cnt = Counter(nums)
most_1 = cnt.most_common(1)[0][0]
range_set = set(list(range(1, len(nums)+1)))
num_set = set(nums)
miss_num = range_set - num_set
if len(list(miss_num)) != 0:
miss_num = list(miss_num)[0]
return [most_1, miss_num]
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 703. Kth Largest Element in a Stream (Python) (0) | 2020.09.21 |
---|---|
[leetCode] 1189. Maximum Number of Balloons (Python) (0) | 2020.09.20 |
[leetCode] 191. Number of 1 Bits (Python) (0) | 2020.09.18 |
[leetCode] 705. Design HashSet (Python) (0) | 2020.09.17 |
[leetCode] 1356. Sort Integers by The Number of 1 Bits (Python) (0) | 2020.09.16 |
Comments