136. Single Number
- Total Accepted: 139245
- Total Submissions: 273783
- Difficulty: Medium
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?
Subscribe to see which companies asked this question
思考:又是一道使用异或的题目。
public class Solution {
public int singleNumber(int[] nums) {
int ret = 0;
for(int i = 0; i < nums.length; ++i){
ret ^= nums[i];
}
return ret;
}
}