LeetCode树 常见的题型以及要注意的点

博客围绕LeetCode中tree相关题目展开,指出要注意区分binary tree、binary search tree和n - ary tree,介绍常见题型,如遍历、求深度、构建树等,还列举众多具体题目,并强调解题时要有题感,考虑递归解法、遍历变形,做好边界判断,最后提及BST相关高频题目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要注意的点:
注意题目说的是binary tree, binary search tree, 还是n-ary tree.

截止到现在 大约有91道tree的题目在leetcode里面
https://darktiantian.github.io/LeetCode%E7%AE%97%E6%B3%95%E9%A2%98%E6%95%B4%E7%90%86%EF%BC%88%E4%BA%8C%E5%8F%89%E6%A0%91%E7%AF%87%EF%BC%89Tree/
常见的题型:
Binary/N-ary tree pre/in/post/level order traverse. do it iteratively and recursively.
Max/Min depth of binary tree/N-ary trree
construct BT from Pre/in/post(choose two)
serialize and deserialize binary tree/N-ary tree

其他的就是一些千奇百怪的题目了 如果不是能深入的理解tree的题目该从何处着手 一定会很难受 毕竟变化多端。

100 same tree
101 symmetric tree
104/559 Min/Max depth of binary/N-ary tree
572 Subtree of another tree
107 binary level order traversal 2
637 average of levels in binary tree /515 find largest value in each tree --求层次遍历中的每一层的平均值和最大值
257 print tree path / 988 smallest string starting from leaf / 112 path sum/ 113 path sum 2
110 check if balanced binary tree
404 sum of left leaves
958. Check Completeness of a Binary Tree
959. Diameter of Binary Tree
960. Univalued Binary Tree
961. Second Minimum Node In a Binary Tree
962. Cousins in Binary Tree
236. Lowest Common Ancestor of a Binary Tree
513. Find Bottom Left Tree Value
662. Maximum Width of Binary Tree
222. Count Complete Tree Nodes
1161. Maximum Level Sum of a Binary Tree
1123. Lowest Common Ancestor of Deepest Leaves
1372. Longest ZigZag Path in a Binary Tree
1367. Linked List in Binary Tree
124. Binary Tree Maximum Path Sum
129. Sum Root to Leaf Numbers
114. Flatten Binary Tree to Linked List
116. Populating Next Right Pointers in Each Node
117. Populating Next Right Pointers in Each Node 2
655. Print Binary Tree
307. Range Sum Query - Mutable

要注意的点:
要有题感 能感觉出来这个问题是不是可以用递归去解 想明白我们是用(递归函数的含义是什么?一层递归还是两层递归(helper函数)?递归等式如何去写?)
这道题可以用pre/in/post/level order的变形去解吗?
root == null 判断了吗?当递归到叶子节点的处理情况写了吗?

BST:
1382. Balance a Binary Search Tree
108 convert sorted array to BST
235 Lowest Common Ancestor of a BST(这个算是很高频的题目了吧)
938 range sum of BST
530 Minimum Absolute Difference in BST / 783. Minimum Distance Between BST Nodes
653.Two Sum IV - Input is a BST
963. Search in a BST
964. Kth Smallest Element in a BST
98. Validate Binary Search Tree
109. Convert Sorted List to Binary Search Tree
450. Delete Node in a BST
1373. Maximum Sum BST in Binary Tree
501. Find Mode in Binary Search Tree

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值