(This question is a variation of the LeetCode question 112. Path Sum. If you haven't completed that question yet, it is recommended to solve it first.)
Given the root of a binary tree, where each node has an integer value, find the root-to-leaf pathwith the minimum sum.
A root-to-leaf path is defined as a sequence of nodes starting from the root and ending at any leaf node (a node with no children). The path sum is the sum of the values of all nodes along that path.
Return a list of integers representing the node values of the minimum sum path, in order from root to leaf. If multiple paths tie for the minimum sum, you may return any one of them.
Constraints:
- 1 ≤ The number of nodes ≤
- -1000 ≤
Node.val≤ 1000
Example 1:
Input: root = [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1] Output: [5, 8, 4, 1] Explanation: There are four root-to-leaf paths in the tree:
- Path 5 → 4 → 11 → 7 has sum 27
- Path 5 → 4 → 11 → 2 has sum 22
- Path 5 → 8 → 13 has sum 26
- Path 5 → 8 → 4 → 1 has sum 18
The path [5, 8, 4, 1] has the minimum sum of 18.
Example 2:
Input: root = [10, 5, -3, 3, 2, null, 11, 3, -2, null, 1] Output: [10, 5, 3, -2]
Example 3:
Input: root = [1, 2, 3] Output: [1, 2]

