题解 | #寻找唯一重复数#
寻找唯一重复数
http://www.nowcoder.com/practice/8dad38b5d6514a51b543b0d9f1bfd88e
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型ArrayList
* @return int整型
*/
public int findRepeatNum (ArrayList<Integer> nums) {
// write code here
if (1 == nums.size()) {
return -1;
}
int[] sign = new int[nums.size()];
int res = 0;
for (int i = 0; i < nums.size(); i++) {
sign[nums.get(i)]++;
if (sign[nums.get(i)] == 2) {
res = nums.get(i);
break;
}
}
return res;
}
}