9296528a9de4057be5bb81349eafbedd
(难度Medium) Problem 113. Path Sum II(路径和II)

Path Sum II

Difficulty

Medium

Description

Given a binary tree and a sum, find all root-to-leaf paths where each path's
sum equals the given sum.

Note: A leaf is a node with no children.

Example:

Given the below binary tree and sum = 22,

      **5**
     **/ \**
    **4   8**
   **/**   / **\**
  **11**  13  **4**
 /  **\**    **/** \
7    **2**  **5**   1

Return:

[
   [5,4,11,2],
   [5,8,4,5]
]

题意

给定一棵带有值的二叉树,和一个整数sum,要求所有从树根到叶子路径和等于sum路径。

题解

top Created with Sketch.