题目描述:
Given a non-empty array of integers, every element appears twice except for one. Find that single one.
给定一个非空的整数数组,除了一个元素外,每个元素都会出现两次。找出那个单一的整数。
最常规的思路就是进行循环,统计出现的数字,只出现一次的就是我们要的答案了
for循环统计数字出现次数
class Solution {
public int singleNumber(int[] nums) {
int[] result = new int[nums.length];
int count = 0;
for (int i = 0;i < nums.length; i++){
for (int j = 0;j <= count;j++){
if (j == count){
result[j] = -1;
count++;
j = count +1;
}else if (nums[i] == nums[j]){
result[j]++;
count++;
j = count + 1;
}
}
}
for (int k &#