Wins the Offer (Java version) Forty-fifth problem: an array of integers in addition to the two figures, other figures appear twice. Please write a program to find these two figures appear only.

/ *
An array of integers in addition to the two figures, other figures appear twice. Please write a program to find these two figures appear only.
* /

import java.util. *;

public class Class45 {

public void FindNumsAppearOnce(int[] array, int num1[], int num2[]){
ArrayList<Integer> list = new ArrayList<Integer>();
Arrays.sort(array);
for(int i = 0; i < array.length; i++){
if((i + 1 < array.length) && (array[i] == array[i + 1])){
i++;
}else{
list.add(array[i]);
}
}
if(list.size() != 0){
num1[0] = list.get(0);
num2[0] = list.get(1);
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub

}

}

Guess you like

Origin www.cnblogs.com/zhuozige/p/12523564.html