1
class Solution {
2
public int singleNonDuplicate(int[] nums) {
3
if (nums.length == 1) return nums[0];
4
int l = 0;
5
int h = nums.length - 1;
6

7
while (l < h) {
8
int mid = l + (h - l) / 2; // divide the array
9

10
if (nums[mid] == nums[mid + 1]) mid = mid - 1; // two same elements should be in same half
11

12
if ((mid - l + 1) % 2 != 0)
13
h = mid; // checking the length of left half. If its is odd then update ur right pointer to
14
// mid
15
else l = mid + 1; // else your right half will be odd then update your left pointer to mid+1
16
}
17

18
return nums[l]; // left pointer will have the answer at last
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0