摘要: Binary Tree Level Order Traversal二叉树的层序遍历两种方式:1、用两个queue交替表示每一层的节点2、用两个node,一个表示当前层的最后一个节点,一个表示下一层的最后一个节点/** * Definition for a binary tree node. * pu... 阅读全文
posted @ 2015-08-18 19:53 懒人部落 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Binary Tree Inorder Traversal即二叉树的中序遍历。常见的有两种方法:递归和循环,其中递归调用的栈空间为树的高度,一般为o(logn),循环方式需要开辟一个栈来保存元素,空间复杂度也是o(logn)tips: 递归比循环耗时,递归:400ms,循环:220ms另外还以一种方... 阅读全文
posted @ 2015-08-18 15:03 懒人部落 阅读(605) 评论(0) 推荐(0) 编辑
摘要: Binary Search Tree IteratorImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callin... 阅读全文
posted @ 2015-08-18 10:58 懒人部落 阅读(200) 评论(0) 推荐(0) 编辑