We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 716582b commit 3c6ed62Copy full SHA for 3c6ed62
Modified Binary Search/540_Single_Element_in_a_Sorted_Array.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public int singleNonDuplicate(int[] nums) {
3
+ if (nums == null || nums.length == 0) {
4
+ return 0;
5
+ }
6
+
7
+ int start = 0, end = nums.length - 1;
8
9
+ while (start < end) {
10
+ int mid = start + (end - start) / 2;
11
12
+ if (mid % 2 == 0) {
13
+ if (nums[mid] == nums[mid + 1]) {
14
+ start = mid + 1;
15
+ } else {
16
+ end = mid;
17
18
19
+ if (nums[mid] == nums[mid - 1]) {
20
21
22
23
24
25
26
27
+ return nums[start];
28
29
+}
0 commit comments