88、合并两个有序数组
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
nums1[:] = sorted((nums1[:m] + nums2[:n]))
89、格雷编码
class Solution:
def grayCode(self, n: int) -> List[int]:
if n == 0:
return [0]
ans = [0, 1]
for i in range(1, n):
for num in ans[::-1]:
ans.append(2**i+num)
return ans
104、二叉树的最大深度
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if not root:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))