Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- leetcode풀이
- 릿코드풀기
- binary search
- 알고리즘풀이
- 상가수익률계산기
- python zip_longest
- python sorted
- 릿코드
- 알고리즘풀기
- python priority queue
- 파이썬 알고리즘
- 릿코드풀이
- 파이썬알고리즘풀기
- 릿코드 풀기
- 릿코드 파이썬
- 파이썬 알고리즘 풀기
- 잇츠디모
- 파이썬 프로그래머스
- 파이썬릿코드풀기
- python 릿코드
- python Leetcode
- LeetCode
- 코틀린기초
- 파이썬 릿코드
- 파이썬릿코드
- leetcode풀기
- python 알고리즘
- leetcode 풀기
- 파이썬알고리즘
- python xor
Archives
- Today
- Total
소프트웨어에 대한 모든 것
LeetCode 풀기 - 260. Single Number III 본문
반응형
260. Single Number III
https://leetcode.com/problems/single-number-iii/
Single Number III - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
제목
문제)

솔루션1)
HashMap or HashSet 자료구조를 통해서 중복을 제거하고 single number만 남겨서 문제를 해결한다.
아래 코드에서는 HashMap 사용.
시간 복잡도 : O(N)
공간 복잡도 : O(N)
class Solution:
def singleNumber(self, nums: List[int]) -> List[int]:
# Hash
d = {}
for n in nums:
if n in d:
del d[n]
else:
d[n] = None
return list(d.keys())
솔루션2)
Counter() 객체를 사용해서 1번 반복된 숫자를 찾는다.
시간 복잡도 : O(N)
공간 복잡도 : O(N)
class Solution:
def singleNumber(self, nums: List[int]) -> List[int]:
counter = Counter(nums)
return [n for n, freq in counter.items() if freq == 1]
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
LeetCode 풀기 - 890. Find and Replace Pattern (0) | 2021.11.09 |
---|---|
LeetCode 풀기 - 441. Arranging Coins (0) | 2021.11.09 |
LeetCode 풀기 - 1732. Find the Highest Altitude (0) | 2021.11.09 |
LeetCode 풀기 - 797. All Paths From Source to Target (0) | 2021.11.08 |
LeetCode 풀기 - 1688. Count of Matches in Tournament (0) | 2021.11.08 |
Comments