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