540-Single-Element-In-A-Sorted-Array
Sat 17 May 2025
https://leetcode.com/problems/single-element-in-a-sorted-array
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
def singleNonDuplicate(self, nums: List[int]) -> int:
l = 0
r = len(nums) - 1
while l < r:
m = (l + r) // 2
if m % 2 == 1:
m -= 1
if nums[m] == nums[m + 1]:
l = m + 2
else:
r = m
return nums[l]
new Solution().singleNonDuplicate()
Score: 5
Category: leetcode