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[m:m+n] = nums2 # 将nums2合并到nums1中
nums1.sort()
89格雷编码
class Solution:
def grayCode(self, n: int) -> List[int]:
return [i ^ i >> 1 for i in range(1 << n)]
104.二叉树最大深度
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if(root==None):
return 0
else:
return max(self.maxDepth(root.left),self.maxDepth(root.right))+1