首页 > 其他 > 详细

[LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

时间:2017-02-23 23:56:15      阅读:457      评论:0      收藏:0      [点我收藏+]

 

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.

Assume a BST is defined as follows:

  • 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.

 

For example:
Given BST [1,null,2,2],

   1
         2
    /
   2

 

return [2].

Note: If a tree has more than one mode, you can return them in any order.

Follow up: Could you do that without using any extra space? (Assume that the implicit stack space incurred due to recursion does not count).

 

s

 

 

 

 

[LeetCode] Find Mode in Binary Search Tree 找二分搜索数的众数

原文:http://www.cnblogs.com/grandyang/p/6436150.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!