public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型一维数组
* @return int整型一维数组
*/
public int[] FindNumsAppearOnce (int[] array) {
// write code here
if(array == null || array.length == 0){
return new int[]{};
}
if(array.length == 1){
return array;
}
//思路一 先排序 在遍历判断
ArrayList<Integer> list = new ArrayList<>();
Arrays.sort(array);
for(int i = 0;i<array.length;i++){
int next = array[i];
if(i == 0){
if(next != array[i + 1]){
list.add(next);
}
} else if(i == array.length - 1){
if(next != array[i-1]){
list.add(next);
}
} else {
if(next != array[i-1] && next != array[i + 1]){
list.add(next);
}
}
}
int[] result = new int[list.size()];
for(int i =0;i<list.size();i++){
result[i] = list.get(i);
}
return result;
}
}