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



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] 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 |