Given an array of integers, every element appears three times except for one. Find that single one.
1 int singleNumber(int* nums, int numsSize) 2 { 3 if(numsSize==1) 4 return nums[0]; 5 int i,j,k; 6 for(i=1;i<numsSize;i++) 7 { 8 for(j=i-1;j>=0;j--) 9 { 10 if(nums[i]>=nums[j]) 11 { 12 break; 13 } 14 } 15 16 if(j!=i-1) 17 { 18 int temp=nums[i]; 19 for(k=i-1;k>j;k--) 20 { 21 nums[k+1]=nums[k]; 22 } 23 nums[k+1]=temp; 24 } 25 } 26 27 if(nums[0]!=nums[1]) 28 { 29 return nums[0]; 30 } 31 else 32 { 33 for(i=0;i<numsSize-1;i++) 34 { 35 if((nums[i]==nums[i+1])||(nums[i+1]==nums[i+2])) 36 { 37 continue; 38 } 39 else 40 { 41 return nums[i+1]; 42 } 43 } 44 } 45 }
时间: 2024-10-18 05:57:20