![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dp
文章平均质量分 70
mars2014jia
这个作者很懒,什么都没留下…
展开
-
Maximum Product Subarray
public class Solution { public int maxProduct(int[] A) { int maxp = A[0]; int minp = A[0]; int tmp_maxp = maxp; int tmp_minp = minp; int res = A[0];转载 2015-02-23 07:17:03 · 208 阅读 · 0 评论 -
Best Time to Buy and Sell Stock IV
public class Solution { public int maxProfit(int k, int[] prices) { // 这道题我有很大疑惑 ref http://blog.csdn.net/linhuanmars/article/details/23236995 // ref http://www.cnblogs.com/EdwardL转载 2015-04-02 05:29:05 · 222 阅读 · 0 评论 -
Candy 双扫
Candy ref //http://www.cnblogs.com/springfor/p/3877120.html //Trapping Rain Water public class Solution { public int candy(int[] ratings) { /转载 2015-03-31 05:14:32 · 217 阅读 · 0 评论 -
BM 算法和dp算法,不理解的题目
要多看看 dp //一下答案完全不懂 public int numDistinct(String S, String T) { int[][] dp = new int[S.length() + 1][T.length() + 1]; dp[0][0] = 1;//initial for(int j = 1; j转载 2015-03-22 08:21:18 · 378 阅读 · 0 评论 -
Edit Distance
public class Solution { public int minDistance(String word1, String word2) { // 题意讲解的很好http://www.cnblogs.com/springfor/p/3896167.html // 关于初始数组的设计!长度,第一行第一列什么的 in转载 2015-03-21 07:48:32 · 193 阅读 · 0 评论 -
Word Search
1) dfs 2) 维护visited 数组,dp类似 3) 关于最后吧visited这一位清回false的解释 ref http://www.cnblogs.com/springfor/p/3883942.html public class Solution { public boolean exist(char[][] board, String word) {转载 2015-03-17 12:42:10 · 376 阅读 · 0 评论 -
Longest Palindromic Substring
reference http://www.programcreek.com/2013/12/leetcode-solution-of-longest-palindromic-substring-java/ soln1 O(n^2) time, O(1) space public class Solution { public String longestPalindrome(转载 2015-03-10 05:08:04 · 183 阅读 · 0 评论 -
9.9 N queen I and II leetcode 原题
参考来源//http://blog.csdn.net/u011095253/article/details/9158473 public class Solution { //http://blog.csdn.net/u011095253/article/details/9158473 public ArrayList solveNQueens(int n) {转载 2015-02-11 00:17:39 · 224 阅读 · 0 评论 -
Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to转载 2015-03-07 03:09:38 · 186 阅读 · 0 评论 -
天题之 三维数组dp Scramble String
public class Solution { public boolean isScramble(String s1, String s2) { // 讲解 http://blog.csdn.net/fightforyourdream/article/details/17707187 // 代码 http://www.blogjava.net/sandy/转载 2015-03-26 07:12:02 · 450 阅读 · 0 评论 -
天题之 交织的字符串 二维dp规划,Interleaving String
首先别的不说,看懂题目都比较费劲 其实还好 public class Solution { public boolean isInterleave(String s1, String s2, String s3) { // ref http://www.cnblogs.com/springfor/p/3896159.html if(s1.le转载 2015-03-26 07:15:06 · 244 阅读 · 0 评论 -
Permutations
public ArrayList> permute(int[] num) { ArrayList> res = new ArrayList>(); if(num==null || num.length==0) return res; ArrayList t = new ArrayList(); t.add(num[0]); res.a原创 2015-03-19 09:13:21 · 198 阅读 · 0 评论 -
Permutations II
public class Solution { public ArrayList> permuteUnique(int[] num) { // use hashset to keep uniqueness, 其他和I一样 ArrayList> res = new ArrayList>(); if(num==null || num.length原创 2015-03-19 11:18:48 · 154 阅读 · 0 评论 -
dp 专题:1 Word Break I II
参考代码 http://needjobasap.blogspot.com/2014/11/word-break-leetcode.html http://fisherlei.blogspot.com/2013/11/leetcode-word-break-solution.html " possible[i] = true if S[0,i]在dictiona原创 2015-02-11 07:29:52 · 318 阅读 · 0 评论 -
Decode Ways
//http://www.cnblogs.com/springfor/p/3896162.html public class Solution { public int numDecodings(String s) { if (s==null||s.length()==0||s == "0") return 0;转载 2015-02-23 12:31:50 · 175 阅读 · 0 评论 -
House Robber
public class Solution { public int rob(int[] num) { // https://leetcode.com/discuss/30020/java-o-n-solution-space-o-1 不是很理解 int prevNo = 0; int prevYes = 0; for (int n : num) {转载 2015-04-01 09:14:03 · 207 阅读 · 1 评论