pull/26/head
chefyuan 2021-05-13 14:28:39 +08:00
parent 3cdbea167c
commit b9301dc262
3 changed files with 76 additions and 1 deletions

View File

@ -50,7 +50,7 @@
****
> **[](https://wwr.lanzous.com/iSGhjox0yne)**
> **[](https://wwr.lanzoux.com/iSGhjox0yne)**
[](https://cdn.jsdelivr.net/gh/tan45du/test@master/微信图片_20210320152235.wp1ysdbibsw.png)进行阅读,两个平台同步更新,另外想要和题友们一起刷题**的同学可以来我的小屋,**点击**刷题小队**进入,另外群里老哥还会不定期发布内推消息,面经等,需要的可以进一下,不过来的时候**记得备注**,希望这个群能对你们有一丢丢帮助吧,一起加油。

View File

@ -0,0 +1,75 @@
, ,`,,`.
![](https://img-blog.csdnimg.cn/20210504155755565.gif)
###
![image](https://cdn.jsdelivr.net/gh/tan45du/test@master/image.622242fm7dc0.png)
[1,2,3]
1 2 3
>
![](https://img-blog.csdnimg.cn/20210512205822221.gif)
root while
O(n)
O(n) O(logn) O(n)
****
```java
class Solution {
public List<Integer> preorderTraversal(TreeNode root) {
List<Integer> list = new ArrayList<>();
Stack<TreeNode> stack = new Stack<>();
if (root == null) return list;
stack.push(root);
while (!stack.isEmpty()) {
TreeNode temp = stack.pop();
if (temp.right != null) {
stack.push(temp.right);
}
if (temp.left != null) {
stack.push(temp.left);
}
//这里也可以放到前面
list.add(temp.val);
}
return list;
}
}
```
### Morris
Morris