随笔分类 - Stack
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express...
阅读全文
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],] 解题思...
阅读全文
摘要:Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())", where the longest
阅读全文
摘要:[解题思路]二叉树的层序遍历通过使用queue来实现,上网搜索了下,发现该题可以使用栈来解决,通过分析执行结果确实是后进先出这里通过定义leftToRight来表示是从左到右还是从右到左从左到右:先加left后加right从右到左:先加right后加leftorderlevel traversal 遍历最后每行添加到result前 判断是leftToRight 还是Right to Left/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * Tr...
阅读全文
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.pub
阅读全文

浙公网安备 33010602011771号