Java solution 8ms using array sorting


  • 0
    D
       public class Solution {
        public int singleNumber(int[] nums) {
            Arrays.sort(nums);
            int size = nums.length;
            int index1 = 0;
            int index2 = 1;
            if (size ==1){return nums[0];}
            while (index1<size-1){
                if (nums[index1] != nums[index2]){break; }
                index1 +=2;
                index2 +=2;
            }
            return nums[index1];
        }    
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.