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
- gs25
- Docker
- 편스토랑 우승상품
- leetcode
- 코로나19
- 캐치카페
- 우분투
- 데이콘
- Kaggle
- SW Expert Academy
- programmers
- 더현대서울 맛집
- 프로그래머스
- AI 경진대회
- Real or Not? NLP with Disaster Tweets
- Git
- hackerrank
- 파이썬
- 맥북
- 프로그래머스 파이썬
- Baekjoon
- ubuntu
- PYTHON
- ChatGPT
- 편스토랑
- 자연어처리
- 백준
- 금융문자분석경진대회
- dacon
- github
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 136. Single Number (Python) 본문
728x90
반응형
Given a non-empty array of integers, every element appears twice except for one. 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,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
Solution
from collections import Counter
class Solution:
def singleNumber(self, nums: List[int]) -> int:
cnt_dict = Counter(nums)
items = cnt_dict.items()
for key, val in items:
if val == 1:
answer = key
break
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 387. First Unique Character in a String (Python) (0) | 2020.06.15 |
---|---|
[leetCode] 88. Merge Sorted Array (Python) (0) | 2020.06.14 |
[leetCode] 412. Fizz Buzz (Python) (2) | 2020.06.13 |
[leetCode] 891. Sum of Subsequence Widths (Python) (0) | 2020.06.11 |
[HackerRank] HackerRank in a String! (Python) (0) | 2020.06.10 |
Comments