Code & Func
2020-03-23

准备按 Tag 过一遍之前刷过的 LeetCode,总结一些常用的技巧和套路。

题目列表

NameNoDifficultyBlog LinkNote
Valid Parentheses20Easyhttps://blog.codeand.fun/2017/09/24/Valid-Parentheses/可以建一个右括号到左括号的map来使代码更加简洁
Simplify Path71Mediumhttps://blog.codeand.fun/2019/03/02/Simplify-Path/用FSM的思想也可以解,可以用stringstreamgetline进行字符串分割
Binary Tree Inorder Traversal94Mediumhttps://blog.codeand.fun/2020/03/24/Binary-Tree-Preorder-Inorder-Postorder-Traversal/递归、栈、莫里斯遍历
Binary Tree Zigzag Level Order Traversal103Mediumhttps://blog.codeand.fun/2018/02/11/Binary-Tree-Zigzag-Level-Order-Traversal/用栈来模拟,可以避免逆序操作
Binary Tree Preorder Traversal144Mediumhttps://blog.codeand.fun/2020/03/24/Binary-Tree-Preorder-Inorder-Postorder-Traversal/递归、栈、莫里斯遍历
Binary Tree Postorder Traversal145Mediumhttps://blog.codeand.fun/2020/03/24/Binary-Tree-Preorder-Inorder-Postorder-Traversal/function对象+lambda表达式可以减少代码冗余。
Evaluate Reverse Polish Notation150Mediumhttps://blog.codeand.fun/2020/03/31/Evaluate-Reverse-Polish-Notation/
Binary Search Tree Iterator173Mediumhttps://blog.codeand.fun/2020/03/31/Binary-Search-Tree-Iterator/可以用递归、栈和莫里斯遍历来实现中序遍历
Verify Preorder Serialization of a Binary Tree331Mediumhttps://blog.codeand.fun/2018/02/19/Verify-Preorder-Serialization-of-a-Binary-Tree/??这道题和栈好像没有关系啊,不用栈去想反而更简单更快
Flatten Nested List Iterator341Mediumhttps://blog.codeand.fun/2018/02/14/Flatten-Nested-List-Iterator/似乎很多用递归能解(但是比较复杂)的题目都可以用栈来简化。同时,用iterator可以有效减少内存消耗。
Decode String394Medium
上一条动态