#501

Find Mode in Binary Search Tree

pupil · 405 · lc easy +24 · verified · 58.5% accepted · 4,104 likes · top 55%

play →

Description

Given the root of a binary search tree (BST) with duplicates, return all the mode(s) — the most frequently occurring values. If multiple modes exist, return them in any order.

The BST is defined such that:

- The left subtree of a node contains only nodes with keys less than or equal to the node's key.

- The right subtree of a node contains only nodes with keys greater than or equal to the node's key.

- Both the left and right subtrees must also be binary search trees.

Example 1:

Input: root = [1,null,2,2]
Output: [2]

Example 2:

Input: root = [0]
Output: [0]

Code

1
2
3
4
5
6
7
8
9