码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:http   nod   lan   occurred   dia   most   key   with   als   

 

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   nod   lan   occurred   dia   most   key   with   als   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!