上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页
摘要: class Solution { public int maxProfit(int k, int[] prices) { int n = prices.length; if(n < 2) return 0; if(k >= n) { int res = 0; for(int i = 1; i < n 阅读全文
posted @ 2020-07-19 15:39 Sexyomaru 阅读(99) 评论(0) 推荐(0) 编辑
摘要: class Solution { public List<Integer> getRow(int rowIndex) { Integer[] res = new Integer[rowIndex+1]; Arrays.fill(res,1); for(int i = 1; i <= rowIndex 阅读全文
posted @ 2020-07-19 14:49 Sexyomaru 阅读(108) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int numDistinct(String s, String t) { int m = s.length(), n = t.length(); int[][] dp = new int[m+1][n+1]; // dp[i][j]表示s前i个包含t 阅读全文
posted @ 2020-07-19 14:23 Sexyomaru 阅读(81) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int maxCoins(int[] nums) { int n = nums.length + 2; int[] points = new int[n]; points[0] = 1; points[n-1] = 1; for(int i = 1; 阅读全文
posted @ 2020-07-19 13:33 Sexyomaru 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 方法一: 动态规划 class Solution { public boolean isInterleave(String s1, String s2, String s3) { int n1 = s1.length(), n2 = s2.length(), n3 = s3.length(); if 阅读全文
posted @ 2020-07-18 20:55 Sexyomaru 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 方法一:暴力搜索 class Solution { private int res = 0; public int pathSum(TreeNode root, int sum) { order(root,sum); return res; } public void order(TreeNode 阅读全文
posted @ 2020-07-16 20:09 Sexyomaru 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 判断二分图,使用染色法 方法一:BFS public boolean isBipartite(int[][] graph) { int n = graph.length; int[] color = new int[n]; // 染色数组 0表示为染色, 1 -1为不同色 for(int i = 0 阅读全文
posted @ 2020-07-16 15:07 Sexyomaru 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 方法一:分治,递归 class Solution { int index = 0; // 全局变量记录遍历到的位置 public String decodeString(String s) { int n = s.length(); StringBuilder sb = new StringBuil 阅读全文
posted @ 2020-07-15 20:32 Sexyomaru 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 方法一:不用统计前缀和,只需要统计前i个数的余数就可以,若之前和的余数和当前和的余数相等则子数组可以整除K,遍历一遍即可 class Solution { public int subarraysDivByK(int[] A, int k) { int n = A.length; Map<Integ 阅读全文
posted @ 2020-07-15 20:13 Sexyomaru 阅读(122) 评论(0) 推荐(0) 编辑
摘要: class Solution { public List<List<Integer>> verticalOrder(TreeNode root) { if(root == null) return new ArrayList<>(); Map<Integer,List<Integer>> map = 阅读全文
posted @ 2020-07-14 19:23 Sexyomaru 阅读(95) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 15 下一页