easy/array 136 실패

This commit is contained in:
sm4640
2026-07-08 22:29:49 +09:00
parent a0cda95b8b
commit 77fea700e9

19
easy/array/136.py Normal file
View File

@@ -0,0 +1,19 @@
# Single Number
class Solution:
def singleNumber(self, nums: list[int]) -> int:
result = 0
for num in nums:
result ^= num
return result
"""
걸린 시간: 몰라
시간 복잡도: 모든 요소를 보기 때문에 O(n)이고, 추가 자료구조 같은 것을 쓰지 않기 때문에 공간복잡도는 O(1)이다.
해설: 공간복잡도를 O(1)로 할 수 있는 방법이 떠오르지 않았다.
2개의 같은 수는 XOR 비트 연산을 진행하면 0이 된다는 규칙을 이용하여 문제를 해결할 수 있다.
"""