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

two bst iterator

时间:2018-08-09 18:27:21      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:case   color   动手   tree   ima   pointer   poi   赋值   ted   

bst iterator 

 

 

    1. binary search tree iterator ( in order )  follow up:两个BST,然后按顺序iterate。这个follow up建议大家一定不要想当然,要自己动手写一下,考虑齐全corn case,然后跑出来看看,里面有坑。。写173的人都应该已经有现成的iterator了吧 然后便利两个bst 就是用的两个这样的iterator 每次call next 比较大小 加上我原文中提到的trick就没问题了。。有一个比较巧妙的办法,用Integer 而不是int pointer记录每次iterate到的数字,如果发现Integer cur == null,再call next 赋值。

two bst iterator

标签:case   color   动手   tree   ima   pointer   poi   赋值   ted   

原文地址:https://www.cnblogs.com/tobeabetterpig/p/9450636.html

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