376.Binary Tree Path Sum

1.Description(Easy)

Given a binary tree, find all paths that sum of the nodes in the path equals to a given numbertarget.

A valid path is from root node to any of the leaf nodes.

Example

Given a binary tree, and target =5:

     1
    / \
   2   4
  / \
 2   3

return

[
  [1, 2, 2],
  [1, 4]
]

2.Code

Version 1:

Version 2:https://jingjingshao.gitbooks.io/data-structure-and-algorithm-analysis/content/Tree/binary_tree_path_problem.html

Last updated

Was this helpful?