-
[LeetCode] Single Number알고리즘 2019. 12. 6. 16:14
문제
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
Input: [2,2,1] Output: 1
Example 2:
Input: [4,1,2,1,2] Output: 4
Approach
xor 비트연산으로 푼다.
Code
https://github.com/chi3236/algorithm/blob/master/LeetCode_SingleNumber.c
'알고리즘' 카테고리의 다른 글
[LeetCode] Surrounded Regions (0) 2019.12.07 [LeetCode] Longest Consecutive Sequence (0) 2019.12.06 [LeetCode] Word Ladder (0) 2019.12.06 [LeetCode] Valid Palindrome (0) 2019.12.05 [LeetCode] Binary Tree Maximum Path Sum (0) 2019.12.05