【LeetCode】136 & 137 & 260 - Single Number I & II &III
I.
Given an 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?
Hide Similar Problems:
Solution : Xor
class Solution { public: int singleNumber(vector<int>& nums){ int ret=0; //it must be initialized for(int i=0;i<nums.size();i++){ ret=ret^nums[i]; } return ret; } };
II.
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Hide Similar Problems :
Solution :