企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
Given an array of integers, every element appears twice except for one. Find that single one. ``` public class Solution { public int singleNumber(int[] nums) { if(nums.length==1){ return nums[0]; }else if(nums.length%2 == 0){ return 0; }else{ Arrays.sort(nums); int n = nums.length-1; for(int i=0;i<n;i+=2){ if(nums[i] != nums[i+1]){ return nums[i]; } } return nums[n]; } } } ```