def search():
print("Hello, world!" )
return
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
MARKDOWN语法 https://markdown.com.cn/basic-syntax/htmls.html
def search_left_bound(self, arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = left + (right - left) // 2
if arr[mid] <= target:
left = mid + 1
else:
right = mid - 1
return right if right >= 0 else -1
def right_loc(self, nums, target):
# 右边界
left, right = 0, len(nums) - 1
while left <= right: # 闭区间
mid = left + (right - left) // 2
if nums[mid] > target:
right = mid - 1
else:
left = mid + 1
if left < 0 or nums[right] != target:
return -1
return right
def left_loc(self, nums, target):
# 左边界
left, right = 0, len(nums) - 1
while left <= right: # 闭区间
mid = left + (right - left) // 2
if nums[mid] < target:
left = mid + 1
else:
right = mid - 1
if left > len(nums) or nums[left] != target:
return -1
return left