Loading

摘要: 题目 102. 二叉树的层序遍历 思路1(迭代) BFS广度优先搜索 用队列先进先出特性遍历 代码 class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = ne 阅读全文
posted @ 2020-12-07 17:36 linzeliang 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题目 145. 二叉树的后序遍历 思路1(递归) 中序先遍历左孩子,然后右孩子,最后父节点 递归遍历 代码 class Solution { List<Integer> res = new ArrayList<>(); public List<Integer> postorderTraversal( 阅读全文
posted @ 2020-12-07 00:25 linzeliang 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 题目 94. 二叉树的中序遍历 思路1(递归) 中序先遍历左孩子,然后父节点,然后右孩子 递归遍历 代码 class Solution { List<Integer> res = new ArrayList<>(); public List<Integer> inorderTraversal(Tre 阅读全文
posted @ 2020-12-07 00:21 linzeliang 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 题目 144. 二叉树的前序遍历 思路1(递归) 前序先遍历根节点,然后左孩子,然后右孩子 使用递归解题 代码 class Solution { List<Integer> res = new LinkedList<>(); public List<Integer> preorderTraversa 阅读全文
posted @ 2020-12-07 00:18 linzeliang 阅读(71) 评论(0) 推荐(0) 编辑