java.lang.Object
g0501_0600.s0501_find_mode_in_binary_search_tree.Solution

public class Solution extends Object
501 - Find Mode in Binary Search Tree.<p>Easy</p> <p>Given the <code>root</code> of a binary search tree (BST) with duplicates, return <em>all the <a href="https://en.wikipedia.org/wiki/Mode_(statistics)" target="_top">mode(s)</a> (i.e., the most frequently occurred element) in it</em>.</p> <p>If the tree has more than one mode, return them in <strong>any order</strong>.</p> <p>Assume a BST is defined as follows:</p> <ul> <li>The left subtree of a node contains only nodes with keys <strong>less than or equal to</strong> the node&rsquo;s key.</li> <li>The right subtree of a node contains only nodes with keys <strong>greater than or equal to</strong> the node&rsquo;s key.</li> <li>Both the left and right subtrees must also be binary search trees.</li> </ul> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/11/mode-tree.jpg" alt="" /></p> <p><strong>Input:</strong> root = [1,null,2,2]</p> <p><strong>Output:</strong> [2]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> root = [0]</p> <p><strong>Output:</strong> [0]</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> <p><strong>Follow up:</strong> Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findMode

      public int[] findMode(TreeNode root)