#257

Binary Tree Paths

pupil · 300 · lc easy +20 · verified · 68.3% accepted · 7,213 likes · top 75%

play →

Description

Given the root of a binary tree, collect every path from root to leaf and return them. A leaf is any node that has no children. The paths may be returned in any order.

Example 1:

Input: root = [1,2,3,null,5]
Output: ["1->2->5","1->3"]

Example 2:

Input: root = [1]
Output: ["1"]

Code

1
2
3
4
5
6
7
8
9