java.lang.Object
g0501_0600.s0508_most_frequent_subtree_sum.Solution

public class Solution extends Object
508 - Most Frequent Subtree Sum.<p>Medium</p> <p>Given the <code>root</code> of a binary tree, return the most frequent <strong>subtree sum</strong>. If there is a tie, return all the values with the highest frequency in any order.</p> <p>The <strong>subtree sum</strong> of a node is defined as the sum of all the node values formed by the subtree rooted at that node (including the node itself).</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/04/24/freq1-tree.jpg" alt="" /></p> <p><strong>Input:</strong> root = [5,2,-3]</p> <p><strong>Output:</strong> [2,-3,4]</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/04/24/freq2-tree.jpg" alt="" /></p> <p><strong>Input:</strong> root = [5,2,-5]</p> <p><strong>Output:</strong> [2]c</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

    • findFrequentTreeSum

      public int[] findFrequentTreeSum(TreeNode root)