Single Number II 落单的数 II
Description
Given 3*n + 1 non-negative integer, every numbers occurs triple times except one, find it.
public class Solution {
/**
* @param A: An integer array
* @return: An integer
*/
public int singleNumberII(int[] A) {
// write your code here
if(A.length == 1){
return A[0] ;
}
Arrays.sort(A) ;
for(int i = 0 ; i < A.length ; i = i+3){
if(i < A.length-2 && A[i] != A[i+2] ){
return A[i] ;
}
}
return A[A.length-1] ;
}
}
2142

被折叠的 条评论
为什么被折叠?



