标签:
Given an array of integers, every element appears three times except for one. Find that single one.
代码如下:
1 public class Solution { 2 public int singleNumber(int[] nums) { 3 if(nums.length==1||nums.length==2) 4 return nums[0]; 5 Arrays.sort(nums); 6 for(int i=0;i<nums.length-2;) 7 { 8 if(nums[i]==nums[i+1]&&nums[i]==nums[i+2]) 9 i=i+3; 10 else return nums[i]; 11 } 12 return nums[nums.length-1]; 13 } 14 }
标签:
原文地址:http://www.cnblogs.com/ghuosaao/p/5479013.html