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

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
Example:
Input: [1,2,1,3,2,5]
Output: [3,5]
Note:
- The order of the result is not important. So in the above example, [5, 3] is also correct.
- Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
Solution
from collections import Counter
class Solution:
def singleNumber(self, nums: List[int]) -> List[int]:
cnt = Counter(nums)
cnt_list = list(cnt.items())
answer = [x[0] for x in cnt_list if x[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] 349. Intersection of Two Arrays (Python) (1) | 2020.07.30 |
|---|---|
| [leetCode] 1185. Day of the Week (Python) (0) | 2020.07.29 |
| [leetCode] 445. Add Two Numbers II (Python) (0) | 2020.07.27 |
| [leetCode] 1360. Number of Days Between Two Dates (Python) (0) | 2020.07.26 |
| [leetCode] 1154. Day of the Year (Python) (0) | 2020.07.25 |
Comments