树
姜小园大猪蹄子本人
这个作者很懒,什么都没留下…
展开
-
437. 路径总和 III
留个坑,这个题我不会,但是我想等熟悉了HashMap然后再过来写 好像还要学习一下回溯原创 2020-06-17 22:44:16 · 75 阅读 · 0 评论 -
543. 二叉树的直径
class Solution { int res = 0; public int diameterOfBinaryTree(TreeNode root) { if(root == null) return 0; depth(root); return res; } public int depth(TreeNode root){ if(root == null) return 0; int left = depth(root.l.原创 2020-06-15 23:24:00 · 90 阅读 · 0 评论 -
101. 对称二叉树
public static boolean isSymmetric(TreeNode root) { if(root==null) return true; Queue<TreeNode> a = new LinkedList<>(); Queue<TreeNode> b = new LinkedList<>(); if(root.left==null&&root.right=...原创 2020-06-14 16:15:53 · 103 阅读 · 0 评论 -
104.二叉树的最大深度
1、stack还可以用Pair 2、max判断的位置选的好 class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; int max = 0; Stack<Pair<TreeNode,Integer>> stack = new Stack<>(); stack.push(new Pair(r原创 2020-05-27 09:21:23 · 90 阅读 · 0 评论 -
226. 翻转二叉树
栈也可以、队列也可以,能够遍历整个二叉树就可以把它们交换 栈的方法 class Solution { public TreeNode invertTree(TreeNode root) { TreeNode newtree = root; if(root==null) return root; Stack<TreeNode> newstack = new Stack(); newstack.push(root);原创 2020-05-25 15:36:09 · 133 阅读 · 0 评论 -
617.合并二叉树
二叉树原创 2020-05-23 22:08:48 · 105 阅读 · 0 评论