随笔分类 - LeetCode热门200题题库
摘要:本体关键就是二叉树加递归 在递归中用int数组保存需要的内容 //二叉树加递归 注意int[]返回值很关键 public class L333 { private int ans; public int largestBSTSubtree(TreeNode root) { isBST(root);
阅读全文
摘要:动态规划 public int minCost(int[][] costs) { int[][] dp=new int[costs.length][3]; dp[0][0]=costs[0][0]; dp[0][1]=costs[0][1]; dp[0][2]=costs[0][2]; for(in
阅读全文
摘要:class Solution { public boolean verifyPreorder(int[] preorder) { LinkedList<Integer> stack=new LinkedList<>(); int preElem=Integer.MIN_VALUE; for(int
阅读全文
摘要:构建二叉树的题 class Solution { public TreeNode upsideDownBinaryTree(TreeNode root) { if(root==null){ return null; } if(root.left==null){ return root; } Tree
阅读全文