摘要: 124.二叉树的最大路径和 public int maxPathSum(TreeNode root) { if(root == null) { return 0; } return process(root).max; } public Info process(TreeNode root) { i 阅读全文
posted @ 2022-02-15 16:34 现在开始努力 阅读(32) 评论(0) 推荐(0)
摘要: 188.买卖股票的最佳时机4 public int maxProfit(int k, int[] prices) { if (prices == null || prices.length == 0) { return 0; } int N = prices.length; if (k >= N / 阅读全文
posted @ 2022-02-14 17:07 现在开始努力 阅读(53) 评论(0) 推荐(0)
摘要: 116.填充每个节点的下一个右侧节点 public Node connect(Node root) { if(root == null) { return null; } MyQueue myQueue = new MyQueue(); myQueue.add(root); while(!myQue 阅读全文
posted @ 2022-02-11 16:54 现在开始努力 阅读(33) 评论(0) 推荐(0)
摘要: 剑指Offer 47 public int maxValue(int[][] grid) { int M = grid.length; int N = grid[0].length; int dp[][] = new int[M][N]; dp[0][0] = grid[0][0]; for(int 阅读全文
posted @ 2022-01-26 16:34 现在开始努力 阅读(25) 评论(0) 推荐(0)
摘要: 103.二叉树的锯齿形层序遍历 public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if(root == null) { return re 阅读全文
posted @ 2022-01-25 15:38 现在开始努力 阅读(63) 评论(0) 推荐(0)
摘要: 91.解码方法 public int numDecodings(String s) { char s1[] = s.toCharArray(); int N = s1.length; int dp[] = new int[N + 1]; dp[N] = 1; for(int index = N -  阅读全文
posted @ 2022-01-24 15:26 现在开始努力 阅读(31) 评论(0) 推荐(0)
摘要: 76.覆盖最小子串 public String minWindow(String s, String t) { if(s.length() < t.length()) { return ""; } char s1[] = s.toCharArray(); char t1[] = t.toCharAr 阅读全文
posted @ 2022-01-24 10:34 现在开始努力 阅读(41) 评论(0) 推荐(0)
摘要: 66.加一 public int[] plusOne(int[] digits) { int N = digits.length; for(int i = N - 1;i >= 0;i --) { if(digits[i] < 9) { digits[i] ++; return digits; } 阅读全文
posted @ 2022-01-19 15:59 现在开始努力 阅读(30) 评论(0) 推荐(0)
摘要: 53.最大子数组和 public int maxSubArray(int[] nums) { int res = Integer.MIN_VALUE; int curRes = 0; if(nums == null || nums.length == 0) { return 0; } for(int 阅读全文
posted @ 2022-01-17 17:00 现在开始努力 阅读(28) 评论(0) 推荐(0)
摘要: 687.最长同值路径 public int longestUnivaluePath(TreeNode root) { if(root == null) { return 0; } return process(root).notBeginX - 1; } public Info process(Tr 阅读全文
posted @ 2022-01-11 16:41 现在开始努力 阅读(21) 评论(0) 推荐(0)