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
- Real or Not? NLP with Disaster Tweets
- 프로그래머스 파이썬
- 캐치카페
- SW Expert Academy
- 편스토랑
- hackerrank
- Git
- 우분투
- 프로그래머스
- 맥북
- 데이콘
- dacon
- gs25
- ubuntu
- ChatGPT
- PYTHON
- Docker
- 금융문자분석경진대회
- Baekjoon
- 백준
- 코로나19
- leetcode
- 더현대서울 맛집
- Kaggle
- 파이썬
- 자연어처리
- AI 경진대회
- programmers
- github
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 137. Single Number II (Python) 본문
728x90
반응형
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
Input: [2,2,3,2]
Output: 3
Example 2:
Input: [0,1,0,1,0,1,99]
Output: 99
Solution
from collections import Counter
class Solution:
def singleNumber(self, nums: List[int]) -> int:
answer = 0
cnt = dict(Counter(nums))
keys = cnt.keys()
for key in keys:
if cnt[key] == 1:
answer = key
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 386. Lexicographical Numbers (Python) (0) | 2020.07.22 |
---|---|
[leetCode] 172. Factorial Trailing Zeroes (Python) (0) | 2020.07.21 |
[leetCode] 383. Ransom Note (Python) (0) | 2020.07.19 |
[leetCode] 9. Palindrome Number (Python) (0) | 2020.07.18 |
[leetCode] 819. Most Common Word (Python) (0) | 2020.07.17 |
Comments