leetcode 0205

700 二叉搜索树中的搜索

https://leetcode-cn.com/problems/search-in-a-binary-search-tree

175 组合两个表

表1: Person

+-------------+---------+
| 列名         | 类型     |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId 是上表主键
表2: Address

+-------------+---------+
| 列名         | 类型    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+

AddressId 是上表主键

编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:FirstName, LastName, City, State

仍旧不理解 left join

select FirstName, LastName, City, State 
from Person left join Address
on Person.PersonId = Address.PersonId;

590. N叉树的后序遍历

递归:

这个思路还是 递归的,下面是迭代的提升:

迭代:

思路: 迭代进行了 NRL 的先序 迭代 遍历,然后reverse NRL 到 LRN 就是 要求的后序遍历了啊。ok

589 N叉树的前序遍历

https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal

递归, 注意 递归 过程中附带的 action 的位置

位置在前面,因为是先序(对比上面的后序遍历, 你可以看到后序遍历的 ans.add(root.val) 在后面。

迭代实现,如何正确入栈(倒序children 入栈,才是先序的正确姿势)

为什么先/前序遍历需要 用 stack ,而不是 queue(以及阐明:层序遍历确实需要queue)

posted on 2020-02-05 11:42  Paulkg12  阅读(194)  评论(0编辑  收藏  举报

导航