Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Binary Tree Paths

XPChallenge Points: 10
levelLevel: Easy

You are given the root of a binary tree.
Your task is to return all the paths from the root node to each leaf node in any order.

A leaf node is defined as a node that has no left or right child.

Each path should be represented as a string, where node values are connected by "->".

Example 1:

Input: root = [10, 5, 15, null, 7]

Output: ["10->5->7", "10->15"]

Example 2:

Input: root = [8]

Output: ["8"]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result