码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
BFS广度遍历代码模板
BFS广度遍历代码模板 /** 广度遍历代码模板 */ public class TestBFS { public List<List<Integer>> bsf(TreeNode root) { // 如果节点为空 if (root == null) { return null; } List<L ...
分类:其他好文   时间:2020-07-13 18:26:06    阅读次数:70
LeetCode94二叉树中序遍历
题目链接 https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 题解一:递归 // Problem: LeetCode 94 // URL: https://leetcode-cn.com/problems/binary-tr ...
分类:其他好文   时间:2020-07-13 15:36:49    阅读次数:58
LeetCode144二叉树前序遍历
题目链接 https://leetcode-cn.com/problems/binary-tree-preorder-traversal/description/ 题解一:递归 // Problem: LeetCode 144 // URL: https://leetcode-cn.com/prob ...
分类:其他好文   时间:2020-07-13 00:00:50    阅读次数:90
二叉树--层序遍历(leetcode 102
BFS和DFS DFS遍历使用递归(隐式使用栈): void dfs(TreeNode root) { if (root == null) { return; } dfs(root.left); dfs(root.right); } BFS遍历使用队列 void bfs(TreeNode root) ...
分类:其他好文   时间:2020-07-12 22:04:02    阅读次数:66
树的遍历
package july.wild.All_Data_Structure_Impl; import java.util.Stack; /**使用递归一定要有返回值 * @author 郭赛 * @Company Huawei */ public class TreeNode { TreeNode l ...
分类:其他好文   时间:2020-07-12 13:53:22    阅读次数:44
LeetCode 109. 有序链表转换二叉搜索树
给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。 示例: 给定的有序链表: [-10, -3, 0, 5, 9], 一个可能的答案是:[0, -3, 9, -10, null, 5], ...
分类:其他好文   时间:2020-07-12 12:02:11    阅读次数:59
103. 二叉树的锯齿形层次遍历-中等难度
问题描述 给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。 例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回锯齿形层次遍历如下: [ [3], [20,9], [15 ...
分类:其他好文   时间:2020-07-11 21:22:39    阅读次数:47
剑指Offer32-Ⅱ从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:其他好文   时间:2020-07-09 20:53:22    阅读次数:74
LeetCode 112. 路径总和 Java
1.层序遍历,一个队列存放节点,一个队列存放到当前节点的值。 2.递归 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * ...
分类:编程语言   时间:2020-07-07 16:00:52    阅读次数:49
路径总和--leetcode112
方法1:递归 /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool hasPath ...
分类:其他好文   时间:2020-07-07 10:22:49    阅读次数:60
1958条   上一页 1 ... 12 13 14 15 16 ... 196 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!