三个月算法进阶--day64
目录
python listA.append(list(listB))
二叉树递归的过程中记录搜索路径
二叉树搜索的return可仅停止递归
二叉树回溯借助列表pop()
记录
leetcode剑指offer第34题[二叉树中和为某一值的路径]
class Solution:
def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]:
ans, path = [], []
def cur(node, target):
if not node:
return
path.append(node.val)
target -= node.val
if target == 0 and not node.left and not node.right:
ans.append(list(path))
cur(node.left, target)
cur(node.right, target)
path.pop()
cur(root, sum)
return ans
图顶点Vertex/节点Node
具有key,可携带payload
图边Edge/弧Arc
无向或有向
图权重Weight
赋权图,一个顶点到另一个顶点的“代价”
图G=(V, E)
路径Path
无权路径的长度为边的数量,带权路径的长度为所有边权重的和
圈Cycle
首尾顶点相同的路径
有向无圈图DAG
图算法