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 |
Tags
- 프로그래머스 파이썬
- 백준
- AI 경진대회
- 맥북
- github
- 자연어처리
- 코로나19
- 편스토랑
- 데이콘
- 캐치카페
- Baekjoon
- dacon
- gs25
- Real or Not? NLP with Disaster Tweets
- 우분투
- leetcode
- Docker
- 더현대서울 맛집
- 편스토랑 우승상품
- 금융문자분석경진대회
- programmers
- hackerrank
- PYTHON
- ubuntu
- Git
- Kaggle
- SW Expert Academy
- 파이썬
- 프로그래머스
- ChatGPT
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 136. Single Number (Python) 본문
728x90
반응형
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
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
![](http://t1.daumcdn.net/tistory_admin/static/images/no-image-v1.png)
![](https://blog.kakaocdn.net/dn/J2PYa/btqEP25q7u8/9KbSCcATZa1kFfsbP5BUmK/img.png)
![](https://blog.kakaocdn.net/dn/UOYm9/btqEOFcXQxH/EuPjmc38i9SNmcPDtKQnTK/img.png)
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] 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 |