Accepted brute force java solution


  • 0
    V
    public int singleNonDuplicate(int[] nums) {
           int last = nums[0] - 1;
            for (int i = 0; i < nums.length; i++) {
                if (last != nums[i]) {
                    if ((i + 1) == nums.length || nums[i] != nums[i + 1]) return nums[i];
                    i++;
                }
                last = nums[i];
            }
            return last;
        }
    

Log in to reply
 

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