Skip to content

Latest commit

 

History

History
46 lines (30 loc) · 1.17 KB

0257-binary-tree-paths.adoc

File metadata and controls

46 lines (30 loc) · 1.17 KB

257. Binary Tree Paths

{leetcode}/problems/binary-tree-paths/[LeetCode - Binary Tree Paths^]

Given a binary tree, return all root-to-leaf paths.

Note: A leaf is a node with no children.

Example:

Input:

   1
 /   \
2     3
 \
  5

Output: ["1->2->5", "1->3"]

Explanation: All root-to-leaf paths are: 1->2->5, 1->3

思路分析

直接递归就可以搞定。

这次尝试了一下回溯的写法,过程大概如下:

{image_attr}
link:{sourcedir}/_0257_BinaryTreePaths.java[role=include]