N-Repeated Element in Size 2N Array
给一个数组找其中出现n+1次的元素. 已知有且只有一个. 直接做就行了.
1 2 3 4 5 6 7 8 9 10 11 |
class Solution { public int repeatedNTimes(int[] A) { boolean[] test = new boolean[10001]; for(int a : A) { if(test[a]) return a; test[a] = true; } return -1; } } |