2
def lengthOfLIS(self, nums: list[int]) -> int:4
# Initialize the result7
# Binary search to find the index of the smallest number in result that is greater than or equal to the target8
def binarySearch(l, r, target):12
# If the left and right pointers meet, we have found the smallest number that is greater than the target16
# Find the mid pointer19
# If the number at the mid pointer is equal to the target, we have found a number that is equal to the target23
# Else if the number at the mid poitner is less than the target, we search the right side25
return binarySearch(m + 1, r, target)27
# Else, we search the left side including the number at mid pointer because it is one of the possible solution since it is greater than the target29
return binarySearch(l, m, target)31
# Iterate through all numbers34
# If the last number in the result is less than the current number35
if not res or res[-1] < n:37
# Append the current number to the result42
# Else, find the index of the smallest number in the result that is greater than or equal to the current number43
i = binarySearch(0, len(res) - 1, n)45
# Replace the current number at such index