classSolution{publicintsingleNumber(int[] nums){int result =0;for(int num : nums){
result ^= num;}return result;}}
3- ACM 实现
publicclass onceNum {publicstaticintonce(int[] nums){int res =0;for(int i : nums){
res ^= i;}return res;}publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);System.out.println("输入数组长度");int n = sc.nextInt();int[] nums =newint[n];for(int i =0; i < n ;i++){
nums[i]= sc.nextInt();}System.out.println("结果是"+once(nums));;}}