← 返回 amazon 的题目列表Maximum Sum Root-to-Leaf Path in Binary Tree
类型:online_judge
amazon
Print Path from Root to Leaf with the Largest Sum
Given a binary tree, find the path from the root to any leaf node that has the maximum path sum, and output the path.
Input:
A binary tree array stored in level-order fashion. The array element can be an integer or 'null' if the node doesn't exist. The number of nodes in the tree satisfies: 1 <= number of nodes <= 10^4.
Output:
Return the path sequence from root to leaf node that has the maximum sum of node values.
Example Test Cases:
Example 1:
Input: [5,4,8,11,null,13,4,7,2,null,null,null,1]
Output: [5, 4, 11, 7]
Example 2:
Input: [1,2,3]
Output: [1, 3]
Example
Input
[5,4,8,11,null,13,4,7,2,null,null,null,1]