刷题记录
qq_45403704
这个作者很懒,什么都没留下…
展开
-
2021-09-25
确定dp数组(dp table)以及下标的含义 确定递推公式 dp数组如何初始化 确定遍历顺序 举例推导dp数组 斐波那契数列 class Solution { public int fib(int n) { if(n==0||n==1) return n; int sum; int m=0,k=1; for(int i=0;i<n;i++) { ...原创 2021-09-25 21:06:59 · 72 阅读 · 0 评论 -
2021-09-07
平衡二叉树 class Solution { public boolean isBalanced(TreeNode root) { if(root==null) return true; if(Math.abs(cal(root.left)-cal(root.right))>1) { return false; } return isBalanced(root.left)&&原创 2021-09-07 15:39:32 · 70 阅读 · 0 评论 -
2021-09-06
二叉树的前序遍历 class Solution { List<Integer> x=new LinkedList<>(); public List<Integer> preorderTraversal(TreeNode root) { if(root==null) return x; x.add(root.val); preorderTraversal(root.left); preorder原创 2021-09-06 14:11:46 · 81 阅读 · 0 评论 -
2021-09-05
求多叉树最大深度 class Solution { public int maxDepth(Node root) { if(root==null) return 0; int y=0; for(Node x : root.children) { y=Math.max(maxDepth(x),y); } return y+1; } } 二叉树的坡度 class Solutio原创 2021-09-05 17:42:43 · 67 阅读 · 0 评论 -
2021-09-04
中序先序构造二叉树 class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { if (preorder == null || inorder == null || preorder.length != inorder.length || inorder.length < 1) return null; return construct(preor原创 2021-09-04 17:05:08 · 59 阅读 · 0 评论 -
2021.9.3刷题
求根节点到叶节点数字之和 class Solution { static int sum; public int sumNumbers(TreeNode root) { sum=0; Sum(0,root); return sum; } public static void Sum(int val,TreeNode root) { if(root==null) return; int k=原创 2021-09-03 21:05:09 · 68 阅读 · 0 评论 -
2121.9.2刷题
二叉树的最小深度 class Solution { public int minDepth(TreeNode root) { int ans=1000000; if(root==null) return 0; if(root.left==null) { return minDepth(root.right)+1; } if(root.right==null) { .原创 2021-09-02 21:13:23 · 63 阅读 · 0 评论