上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 33 下一页
摘要: 由中序遍历得到数组 用递归构造平衡二叉树 List<Integer> list = new ArrayList<>(); public TreeNode balanceBST(TreeNode root) { //根据数组进行平衡二叉树的创建 inOrder(root); return buildB 阅读全文
posted @ 2020-06-23 09:51 欣姐姐 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 虽然思路是差不多的,但是我自己写的话就越写越繁琐,不能抽丝剥茧言简意赅,最后成了一团乱麻。 那种精巧感还是没办法掌握,一道题解的思想是多么巧妙,但是我自己抽不出来那种主干。 虽菜犹学。 虽菜犹学…… List<Integer> flipped; int index; int[] voyage; pu 阅读全文
posted @ 2020-06-22 17:25 欣姐姐 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 这道题做得比较顺利,但是效果并不是很好 public TreeNode buildTree(int[] preorder, int[] inorder) { if(preorder.length == 0){ return null; } if(preorder.length == 1){ retu 阅读全文
posted @ 2020-06-22 09:25 欣姐姐 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 像这种DFS相关的题型,重点还是要知道如何进行标记。我就是卡在这里顺不下去,难过死了…… public int closedIsland(int[][] grid) { int sum = 0; for(int i = 1;i<grid.length;i++){ for(int j = 1;j<gr 阅读全文
posted @ 2020-06-21 16:27 欣姐姐 阅读(184) 评论(0) 推荐(0) 编辑
摘要: public int[] pondSizes(int[][] land) { List<Integer> list = new ArrayList<>(); int temp; for (int i = 0; i < land.length; i++) { for (int j = 0; j < l 阅读全文
posted @ 2020-06-21 10:49 欣姐姐 阅读(807) 评论(0) 推荐(0) 编辑
摘要: public TreeNode recoverFromPreorder(String S) { Stack<TreeNode> path = new Stack<>(); //构建好栈 //定义一个变量来遍历S int i = 0; //定义一个int变量来确定节点的层数 //先将S转换成char[ 阅读全文
posted @ 2020-06-20 18:00 欣姐姐 阅读(147) 评论(0) 推荐(0) 编辑
摘要: public void flatten(TreeNode root) { if(root == null){ return; }else{ if(root.left == null){ flatten(root.right); }else{ TreeNode node = root; TreeNod 阅读全文
posted @ 2020-06-20 10:34 欣姐姐 阅读(162) 评论(0) 推荐(0) 编辑
摘要: private final static int MAXVALUE = 1000; public int networkDelayTime(int[][] times, int N, int K) { boolean[] visited = new boolean[N+1]; int[][] tim 阅读全文
posted @ 2020-06-20 10:32 欣姐姐 阅读(189) 评论(0) 推荐(0) 编辑
摘要: class Solution { public boolean isBalanced(TreeNode root) { //判断一个树是不是平衡二叉树 //应该是用递归了吧,判断左右子树的高度相差是不是超过1 //但是如何记录树的高度呢,左右子树的高度分别记录的话,应该如何进行呢? if(root 阅读全文
posted @ 2020-06-18 09:23 欣姐姐 阅读(128) 评论(0) 推荐(0) 编辑
摘要: public boolean leafSimilar(TreeNode root1, TreeNode root2) { //要想找到两棵树的叶子节点的值是不是一样,就得通过遍历判断来得到,同时存储在一个数组中 ArrayList<Integer> leaf1 = new ArrayList<>() 阅读全文
posted @ 2020-06-17 20:07 欣姐姐 阅读(155) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 33 下一页