35. Search Insert Position

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You must write an algorithm with O(log n) runtime complexity.

\

Solution:

class Solution:
		def searchInsert(self, nums: List[int], target: int) -> int:
				left, right = 0, len(nums) - 1
				while left <= right:
						mid = (left + right) // 2
						if nums[mid] == target:
								return mid
						elif nums[mid] < target:
								left = mid + 1
						elif nums[mid] > target:
								right = mid - 1
				return left

74. Search a 2D Matrix

You are given an m x n integer matrix matrix with the following two properties:

Given an integer target, return true if target is in matrix or false otherwise.

You must write a solution in O(log(m * n)) time complexity.

\

My solution: