java.lang.Object
g1101_1200.s1161_maximum_level_sum_of_a_binary_tree.Solution

public class Solution extends Object
1161 - Maximum Level Sum of a Binary Tree.<p>Medium</p> <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p> <p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2019/05/03/capture.JPG" alt="" /></p> <p><strong>Input:</strong> root = [1,7,0,7,-8,null,null]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>Level 1 sum = 1.</p> <p>Level 2 sum = 7 + 0 = 7.</p> <p>Level 3 sum = 7 + -8 = -1.</p> <p>So we return the level with the maximum sum which is level 2.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> root = [989,null,10250,98693,-89388,null,null,null,-32127]</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 10<sup>4</sup>]</code>.</li> <li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxLevelSum

      public int maxLevelSum(TreeNode root)