Showing posts with label stack. Show all posts
Showing posts with label stack. Show all posts
Monday, October 15, 2018
Wednesday, September 19, 2018
Sunday, September 9, 2018
Tuesday, May 29, 2018
Wednesday, May 2, 2018
Tuesday, October 17, 2017
Tuesday, September 19, 2017
Tuesday, January 27, 2015
Saturday, January 24, 2015
Monday, January 5, 2015
[LeetCode]Binary Search Tree Iterator
BST中序遍历的迭代器,Inorder遍历iterative版本的好处就体现出来了,我们可以控制停在哪里,而recursive版本的就不好控制。这里我们要决定的是如何找到后继结点,分两种情况,一种是有右子树,那么我们找到右子树最小值即可。第二种是没有右子树,我们pop出栈顶的元素就是后继结点,至于为什么,我们在Binary Tree Preorder Traversal已经证明过这个问题。最后注意一下终止条件即可。
Labels:
binary tree,
leetcode,
stack
Location:
Irvine, CA, USA
[LeetCode]Binary Tree Postorder Traversal
Labels:
binary tree,
leetcode,
stack
Location:
Irvine, CA, USA
[LeetCode]Binary Tree Inorder Traversal
在Binary Tree Preorder Traversal中说明过,Inorder的代码基本上是一样的,只有一行的区别。
Labels:
binary tree,
leetcode,
stack
Location:
Irvine, CA, USA
[LeetCode]Binary Tree Preorder Traversal
BST遍历的问题,很经典的问题。
Labels:
binary tree,
leetcode,
stack
Location:
Irvine, CA, USA
Monday, December 22, 2014
[Algorithm]Convert Expression to Reverse Polish Notation
在Evaluate Reverse Polish Notation中讨论过这个问题,普通式子转换成逆波兰式就要注意两点:第一,由于涉及的运算符都是双目的(不包括括号),运算符要放在第二个操作数后面;第二, 如果第二个操作数,由于运算符号的优先性,是一个表达式,就先写出表示第二个操作数的逆波兰式,之后加上操作符。
Location:
Irvine, CA, USA
[LeetCode]Evaluate Reverse Polish Notation
根据逆波兰式来算出表达式的值。首先说明一下逆波兰式,逆波兰式是巴普通表达式的中缀表达方法,例如,3 + 5 * 4, (3 + 5)* 4 替换成后缀表达式,逆波兰式不需要括号,且不会产生歧义。
Location:
Irvine, CA, USA
Subscribe to:
Posts (Atom)