Here I will write some tip and note I found.
Runtime Speedtips
TIPS: Help you to speed up the submit
Here is the example of the:704. Binary Search
class Solution:
def search(self, nums: List[int], target: int) -> int:
# Init
left,right = 0,len(nums) - 1 # initianlize the index
# Looking for the target
while (left <= right):
middle = left + (right-left) // 2
if nums[middle] == target:
return middle
elif nums[middle] < target:
left = middle + 1
else:
right = middle - 1
# If not found
return -1
The red place is condiction as the more I found the leetcode test answer most of time at the middle.
If I change condiction may runtime-speed up 50%,at the same Memory time