2019-07-10
更新:
增加 Golang
136. Single Number 找出單身狗
❀ Origin
Problem
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
1 | Input: [2,2,1] |
Example 2
1 | Input: [4,1,2,1,2] |
❀ 翻譯
問題
給定一個非空整數字串, 除了一個元素外, 每個元素會出現兩次.
請找出那個單身狗.
注意
- 你的算法應該要有線性的時間複雜度. 你可以完成它, 且不使用額外的記憶體嗎?
❀ Solution
JavaScript
1 | /** |
Golang
1 | func singleNumber(nums []int) (res int) { |