摘要: 1 class Solution { 2 public int rob(TreeNode root) { 3 int[] rootStatus = dfs(root); //存取两种方案结果 4 return Math.max(rootStatus[0], rootStatus[1]); 5 } 6 阅读全文
posted @ 2020-08-06 22:46 小小码农-安 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public boolean canFinish(int numCourses, int[][] prerequisites) { 3 List<List<Integer>> edges = new ArrayList<List<Integer>>(); / 阅读全文
posted @ 2020-08-04 23:03 小小码农-安 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public String addStrings(String num1, String num2) { 3 StringBuilder res = new StringBuilder(); 4 int len1 = num1.length() - 1, l 阅读全文
posted @ 2020-08-03 21:44 小小码农-安 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public void flatten(TreeNode root) { 3 if (root == null) { 4 return; 5 } 6 Deque<TreeNode> stack = new LinkedList<TreeNode>(); 7 阅读全文
posted @ 2020-08-02 21:35 小小码农-安 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public int findMagicIndex(int[] nums) { 3 int len = nums.length; 4 for (int i = 0; i < len; i++){ 5 if (i == nums[i]) 6 return i; 阅读全文
posted @ 2020-07-31 22:49 小小码农-安 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public int integerBreak(int n) { 3 int[] dp = new int[n + 1]; //动态数组 4 for (int i = 2; i <= n; i++) { 5 for (int j = 1; j < i; j+ 阅读全文
posted @ 2020-07-30 22:48 小小码农-安 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public int countOdds(int low, int high) { 3 if(low % 2 == 0 && high % 2 == 0) 4 return (high - low) / 2; 5 if(low % 2 != 0 && hig 阅读全文
posted @ 2020-07-29 23:13 小小码农-安 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val 阅读全文
posted @ 2020-07-28 23:02 小小码农-安 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public int splitArray(int[] nums, int m) { 3 int len = nums.length; 4 int[][] dp = new int[len + 1][m + 1]; //动态规划数组,dp[i][j]代表前i 阅读全文
posted @ 2020-07-28 22:41 小小码农-安 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public boolean isSubsequence(String s, String t) { 3 int len1 = s.length(), len2 = t.length(); 4 int indexs = 0, indext = 0; 5 wh 阅读全文
posted @ 2020-07-27 23:04 小小码农-安 阅读(166) 评论(0) 推荐(0) 编辑