[LeetCode][Python3] 136. Single Number
2018. 9. 27. 23:53 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/single-number/description/
My Solution :
class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ans = 0
for n in nums:
ans ^= n
return ans
Comment :
xor의 아래 2가지 성질을 이용해 풀었다.
n ^ 0 = n
n ^ n = 0
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 169. Majority Element (0) | 2018.10.01 |
---|---|
[LeetCode][Python3] 160. Intersection of Two Linked Lists (0) | 2018.09.28 |
[LeetCode][Python3] 155. Min Stack (0) | 2018.09.28 |
[LeetCode][Python3] 141. Linked List Cycle (0) | 2018.09.28 |
[LeetCode][Python3] 121. Best Time to Buy and Sell Stock (0) | 2018.09.27 |
[LeetCode][Python3] 104. Maximum Depth of Binary Tree (0) | 2018.09.27 |
[LeetCode][Python3] 101. Symmetric Tree (0) | 2018.09.27 |
[LeetCode][Python3] 100. Same Tree (0) | 2018.09.26 |
최근에 달린 댓글 최근에 달린 댓글