- 二分查找
class Solution(object):
def search(self, nums, target):
low = 0
high = len(nums) - 1
while (low <= high):
mid = (high + low) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
high = mid - 1
else:
low = mid + 1
return -1
- 移除元素
class Solution(object):
def removeElement(self, nums, val):
i = 0
j = 0
while j < len(nums):
if (nums[j] != val):
nums[i] = nums[j]
i += 1
j += 1
return i
标签:二分,01,nums,随想录,查找,low,移除
From: https://www.cnblogs.com/miramira/p/18085699