You are given the root of a binary tree. Your task is to return all root-to-leaf paths. Each path should contain the node values from the root to a leaf.
A root-to-leaf path is a path that:
Return a list containing all such paths.
Input: root = [1,2,3,null,5]
Output: [[1,2,5],[1,3]]
Explanation: The tree has two root-to-leaf paths.
Input: root = [1]
Output: [[1]]
Explanation: The root itself forms the only root-to-leaf path.
Input: root = []
Output: []
Explanation: The tree contains no root-to-leaf paths.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 3
1 2 1 3
1 2 3 4 5
1 2 4 1 2 5 1 3