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
- 백준
- 코로나19
- ubuntu
- 맥북
- Baekjoon
- Docker
- Git
- 자연어처리
- Kaggle
- AI 경진대회
- 파이썬
- hackerrank
- 프로그래머스 파이썬
- 우분투
- dacon
- SW Expert Academy
- 데이콘
- PYTHON
- Real or Not? NLP with Disaster Tweets
- leetcode
- gs25
- github
- ChatGPT
- 편스토랑
- 프로그래머스
- 금융문자분석경진대회
- 더현대서울 맛집
- 캐치카페
- programmers
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 442. Find All Duplicates in an Array (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 442. Find All Duplicates in an Array (Python)
솜씨좋은장씨 2020. 10. 13. 22:30728x90
반응형

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
Example:
Input:
[4,3,2,7,8,2,3,1]
Output:
[2,3]
Solution
from collections import Counter
class Solution:
def findDuplicates(self, nums: List[int]) -> List[int]:
cnt_items = Counter(nums).items()
answer = [num[0] for num in cnt_items if num[1] > 1]
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] 215. Kth Largest Element in an Array (Python) (0) | 2020.10.19 |
|---|---|
| [leetCode] 347. Top K Frequent Elements (Python) (0) | 2020.10.14 |
| [leetCode] 504. Base 7 (Python) (0) | 2020.10.12 |
| [leetCode] 1470. Shuffle the Array (Python) (0) | 2020.10.10 |
| [leetCode] 896. Monotonic Array (Python) (0) | 2020.10.09 |
Comments