leetcode-dp
文章平均质量分 82
kainever
这个作者很懒,什么都没留下…
展开
-
House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2015-07-25 22:15:18 · 300 阅读 · 0 评论 -
Wildcard Matching
'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype原创 2015-07-25 22:18:36 · 277 阅读 · 0 评论 -
Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 题目意思 : n步到达,每次可以走一步或两步 , 有多少种原创 2015-07-25 22:17:42 · 290 阅读 · 0 评论 -
Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2015-07-25 22:17:48 · 279 阅读 · 0 评论 -
unique Binary Tree
第一种 : 给定一个数值 n 求它能构成的不同的BST的个数: 这类题,很像那个求斐波那契和,关键就是把状态记录 通过一个数组 把 1 到 i 的BST数目记录 , : 范围大小相等,那么BST的数目一样,接下来就可以直接利用了!public class Solution { public int numTrees(int n) { int[] num =原创 2015-07-25 22:18:58 · 282 阅读 · 0 评论 -
leetcode Stock买 and 卖
在数组中求最大的差值 最大的差值和 两对差值最大 k对差值最大 第一种类型 ; 买进一次 卖出一次 , 求最大差价 ; 思路 : 求P(n) , 可以利用P(n-1)结果,但是 prices[n] 可能小于 前面的最大值或者大于最大值可以通过一个变量记录前面的最小值所在小标,不要关心最大值,求P(n)时,就拿prices[n]与最小值比较 ; if pri原创 2015-07-25 22:18:24 · 422 阅读 · 0 评论 -
Largest Rectangle in Histogram
参考博客: http://blog.csdn.net/doc_sgl/article/details/11805519 Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangl原创 2015-07-25 22:19:38 · 278 阅读 · 0 评论 -
子矩阵问题
矩阵中的最大正方形子矩阵(Maximal Square) 题目描述:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0 比如说,在这个矩阵中,由1构成的最大正方形子矩阵就是4. 题目分析: matrix[ ][ ] 用来存放01,那么当求矩阵[i][j] 的最大矩阵时,用一个 max存放正方形的边长 如果[i][j]原创 2015-07-25 22:21:30 · 516 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2015-07-25 22:18:00 · 315 阅读 · 0 评论 -
关于连续子数组的最大和和最大积
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha原创 2015-07-25 22:18:07 · 438 阅读 · 0 评论 -
Interleaving String(*****)
参考: Leetcode: Interleaving String 递归和DP两种方法解答,解释的很清楚题目:交叉字符串, For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return false.方法一:递归方法每次都是取原创 2015-08-17 21:54:58 · 365 阅读 · 0 评论