- μ²μμλ
sorted(num)
μ΄ κΌ νμν μ€ μμλλ° μ λ ¬μ μ ν΄μ€λ κ²°κ΅ λ¨
- ν·κ°λ¦¬λ©΄ μ§μ λ°°μ΄ exampleμ μκ°ν΄ 보μ
Solution
from typing import List
class Solution:
def singleNumber(self, nums: List[int]) -> int:
answer = 0
for num in sorted(nums):
# answerμ num κ°μ κ³μ μ μ₯νλλ°, "^"μ μ¬μ©νμ¬ μ€λ³΅λ κ°μ΄ μ μ₯λμ§ μκ² ν¨
# λ§μ½ [2(1), 2(2), 1]μ΄λΌκ³ νμ λ,
# 2(1) μ΄λ―Έ μ μ₯λμ΄ μμΌλ©΄ 2(1)κ³Ό 2(1)μ "^" μ°μ°μ 0μ΄ λ¨
# μ¦, μ΅μ’
μ μΌλ‘ μ€λ³΅λμ§ μλ κ°μ΄ μ μ₯λλ κ±°μ§
answer = answer ^ num
return answer
Reference
Leave a comment