diff --git a/easy/array/136.py b/easy/array/136.py new file mode 100644 index 0000000..ee7abd8 --- /dev/null +++ b/easy/array/136.py @@ -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이 된다는 규칙을 이용하여 문제를 해결할 수 있다. +""" + \ No newline at end of file