zoukankan      html  css  js  c++  java
  • 二叉树中和为某一值的所有结果

    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]:
            res = []
            path = []
            def find_path(root, target):
                if not root: return []
                path.append(root.val)
                target -= root.val
                if target == 0 and root.left is None and root.right is None:
                    res.append(path[::])
                
                find_path(root.left, target)
                find_path(root.right, target)
                path.pop()
            find_path(root, sum)
            return res
    
  • 相关阅读:
    stty
    ping
    read
    echo
    grep
    date
    vi与vim编辑器使用
    rename
    netstat
    input输入框的背景图片也可以这样玩
  • 原文地址:https://www.cnblogs.com/KbMan/p/14498134.html
Copyright © 2011-2022 走看看