Skip to content

Commit ee80cf3

Browse files
540_Single_Element_in_a_Sorted_Array(Binary Search)
1 parent 270f37f commit ee80cf3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def singleNonDuplicate(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: int
6+
"""
7+
start, end = 0, len(nums) - 1
8+
while (start < end):
9+
mid = (start + end) // 2
10+
if mid % 2 == 1 :
11+
mid = mid - 1
12+
if nums[mid] != nums[mid + 1]:
13+
end = mid
14+
else:
15+
start = mid + 2
16+
return nums[start]

0 commit comments

Comments
 (0)