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