赞
踩
对我来说,Tree 是 Leetcode中最简单的题,因为Tree的题型比较单一,方法也比较固定。
98. Validate Binary Search Tree https://leetcode.com/problems/validate-binary-search-tree/我觉得这道题和Symmetric Tree比较像都是考察树的结构,要判断这个需要判断左右节点,采用从底到上,以Root为开始,depth-first-search执行得到对所有的结果的判断。
96. Unique Binary Search Trees
https://leetcode.com/problems/unique-binary-search-trees/ 这道题有公式
95. Unique Binary Search Trees II???
101. Symmetric Tree https://leetcode.com/problems/symmetric-tree/
129. Sum Root to Leaf Numbers https://leetcode.com/problems/sum-root-to-leaf-numbers/先序遍历
100. Same Tree
https://leetcode.com/problems/same-tree/
99. Recover Binary Search Tree https://leetcode.com/problems/recover-binary-search-tree/???
116. Populating Next Right Pointers in Each Node
https://leetcode.com/problems/populating-next-right-pointers-in-each-node/??
117. Populating Next Right Pointers in Each Node II
https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/
111. Minimum Depth of Binary Tree
https://leetcode.com/problems/minimum-depth-of-binary-tree/
同path sum, 利用先序遍历记录树的信息。
104. Maximum Depth of Binary Tree
https://leetcode.com/problems/maximum-depth-of-binary-tree/
同样利用先序遍历,记录树的信息。
236. Lowest Common Ancestor of a Binary Tree
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/
遍历左右子树,如果左右孩子不为空,说明遍历到,则认为找到了最小的孩子。
235. Lowest Common Ancestor of a Binary Search Tree
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
如果要找的节点一个是大于当前节点,一个小于当前节点,则现在的节点就是要找的值,否则移向同一侧。
230. Kth Smallest Element in a BST
https://leetcode.com/problems/kth-smallest-element-in-a-bst/
Binary Search Tree的中序遍历的结果是从小到大的顺序,所以记录现在遍历到的节点的值,如果等于Target 就返回该节点。
110. Balanced Binary Tree
https://leetcode.com/problems/balanced-binary-tree/
记录树的高度,并判断左右子树的高度的差的绝对值,如果大于1则不是Balanced Binary tree.从顶往底依次遍历。
144. Binary Tree Preorder Traversal
https://leetcode.com/problems/binary-tree-preorder-traversal/
145. Binary Tree Postorder Traversal
https://leetcode.com/problems/binary-tree-postorder-traversal/
94. Binary Tree Inorder Traversal
https://leetcode.com/problems/binary-tree-inorder-traversal/
三个顺序的Tree的traverse顺序,只是在help函数中访问节点的顺序不同。
102. Binary Tree Level Order Traversal
https://leetcode.com/problems/binary-tree-level-order-traversal/
利用queue进行层序遍历
107. Binary Tree Level Order Traversal II
倒序的层序遍历,每次把结果加到Result的第一个的位置
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。