136. Single Number
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
class Solution {
public:
int singleNumber(vector<int>& nums) {
int rel=0;
for(int i=0;i<nums.size();i++){
rel ^= nums[i];
}
return rel;
}
};
XOR 用到了^這個東西,很有意思
相關文章
- 137-Single Number II
- 260-Single Number III
- Leetcode 137. Single Number IILeetCode
- Leetcode 之 PHP 解析 (260. Single Number III)LeetCodePHP
- 136. 只出現一次的數字
- FSMO(Flexible Single Master Operation)FlexAST
- RMAN Duplicate RAC to Single Instance
- JavaScript Number()JavaScript
- Please specify (single) host string for connection:
- 力扣136.只出現一次的數字力扣
- JavaScript Number 物件JavaScript物件
- Leetcode Number of islandsLeetCode
- Kata:Hamming number
- JavaScript Number toLocaleString()JavaScript
- JavaScript Number toString()JavaScript
- Number.NaNNaN
- leetcode力扣136.只出現一次的數字LeetCode力扣
- Single-spa 原始碼淺析原始碼
- cell single block physical read等待事件BloC事件
- Serial number lookup for Panasonic
- D. The Number of Imposters
- Big Number hd 1212
- 7.104 ITERATION_NUMBER
- Leetcode 447 Number of BoomerangsLeetCodeOOM
- react input[type='number']React
- number(p,s)(轉)
- Last digit of a huge numberASTGit
- [HNU 10072] Fibonacci Number
- Python Number(數字)Python
- Perfect Number 完美數
- [LeetCode] Third Maximum NumberLeetCode
- [LeetCode] Find the Duplicate NumberLeetCode
- Leetcode 9 Palindrome NumberLeetCode
- Number.parseInt() 方法
- Number.parseFloat()方法
- Number.isSafeInteger()方法
- Number.isNaN()方法NaN
- Number.isFinite()方法