图
aaaqqq1234
这个作者很懒,什么都没留下…
展开
-
矩阵中的路径
class Solution: def exist(self, board, word): if not board: return False for i in range(len(board)): for j in range(len(board[0])): if self.dfs(board, i, j, word): return True原创 2020-09-04 15:12:31 · 53 阅读 · 0 评论 -
海洋陆地地图
from collections import deque class Solution: def maxDistance(self, grid): queue = deque() row = len(grid) col = len(grid[0]) res = [[0 for _ in range(row)]for _ in range(col)] visited = [[False for _ in range(ro原创 2020-08-31 13:40:28 · 215 阅读 · 0 评论 -
二叉树所有距离为K的节点
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def distanceK(self, root: TreeNode, target: TreeNode, K: int) -> List[int]: res = [] def df原创 2020-08-31 12:35:49 · 86 阅读 · 0 评论 -
01矩阵
from collections import deque class Solution: def updateMatrix(self, matrix): row = len(matrix) col = len(matrix[0]) res = [[0] * col for _ in range(row)] visited = [[False for _ in range(col)]for _ in range(row)]原创 2020-08-30 22:58:10 · 138 阅读 · 0 评论 -
颜色填充
颜色填充 def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: row = len(image) col = len(image[0]) visited = [[False for _ in range(col)]for _ in range(row)] detection = [[-1,0],[1原创 2020-08-29 22:20:53 · 275 阅读 · 0 评论 -
二叉树的所有路径
dfs def binaryTreePaths(self, root: TreeNode) -> List[str]: if root is None: return [] res = [] def dfs(root,path): path += str(root.val) if root.left is None and root.right is None:原创 2020-08-29 21:42:00 · 84 阅读 · 0 评论