摘要:
public List<List<String>> partition(String s) { int len = s.length(); List<List<String>> totalList = new ArrayList<>(); if(len == 0){ return totalList 阅读全文
摘要:
这道题的动态规划,我自己没有想清楚,看了答案之后才恍然大悟,不难。 public boolean wordBreak(String s, List<String> wordDict) { boolean[] f = new boolean[s.length()+1]; f[0] = true; fo 阅读全文
摘要:
还好做出来了,就是慢了点。 public int numDistinct(String s, String t) { int m = s.length(); int n = t.length(); if(m<n){ return 0; }else if(m ==n){ if(s.equals(t)) 阅读全文
摘要:
import static java.lang.Integer.min; class Solution { public int minDistance(String word1, String word2) { int m = word1.length(); int n = word2.lengt 阅读全文
摘要:
动态规划,还是学不会,,这道题好难啊!!!! 但是思路对了之后又是如此清晰。 public boolean isScramble(String s1, String s2) { if(s1.length() != s2.length()){ return false; } int len = s1. 阅读全文
摘要:
public int maxProfit(int[] prices) { int n = prices.length; if(n<2){ return 0; } int[] f = new int[n]; int[] g = new int[n]; for(int i = 1,valley = pr 阅读全文
摘要:
public int minCut(String s) { int n = s.length(); int[] f = new int[n+1]; boolean[][] p = new boolean[n][n]; for (int i = 0;i<= n;i++){ f[i] = n-1-i; 阅读全文
摘要:
动态规划好巧妙啊啊啊啊啊啊啊 啊 int max =Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { //用动态规划来求解 //DFS //根节点的值、左子树的值、右子树的值、 dfs(root); return max; } pri 阅读全文
摘要:
class Solution { //定义一个数组,用于存放每一列的皇后放置的位置 List<List<String>> result = new ArrayList<>(); public List<List<String>> solveNQueens(int n) { //N皇后 int[] c 阅读全文
摘要:
思路错一点点,努力都是白费。 public String reorganizeString(String S) { int N = S.length(); int[] counts = new int[26]; for (char c: S.toCharArray()) counts[c-'a'] 阅读全文