Dynamic Programming
文章平均质量分 68
iteye_17352
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode - Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0...原创 2015-06-04 08:25:16 · 138 阅读 · 0 评论 -
Leetcode - Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid...原创 2015-04-15 09:41:40 · 93 阅读 · 0 评论 -
Leetcode - Minnum Path
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at...原创 2015-04-15 09:42:31 · 104 阅读 · 0 评论 -
Leetcode - Maximum Subarray
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] has t...原创 2015-04-15 09:43:25 · 95 阅读 · 0 评论 -
Leetcode - 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 th...原创 2015-04-15 09:44:40 · 112 阅读 · 0 评论 -
Leetcode - Trianlge
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], ...原创 2015-04-20 09:26:15 · 96 阅读 · 0 评论 -
Leetcode - Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", whic...原创 2015-04-21 09:13:13 · 108 阅读 · 0 评论 -
Leetcode - Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially po...原创 2015-04-21 09:50:53 · 118 阅读 · 0 评论 -
Leetcode - Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not ...原创 2015-04-23 09:04:36 · 106 阅读 · 0 评论 -
Leetcode - Best Time to Buy and Sell Stock IV
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not enga...原创 2015-05-01 16:11:39 · 120 阅读 · 0 评论 -
Leetcode - Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non...原创 2015-05-01 16:56:24 · 122 阅读 · 0 评论 -
Leetcode - Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input...原创 2015-05-16 16:31:15 · 101 阅读 · 0 评论 -
Leetcode - Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ ...原创 2015-05-17 14:22:51 · 125 阅读 · 0 评论 -
Leetcode - Maximum Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.[balabala] 这题想到借用Largest Rectangle in Histogram的思路就比较简单了。计算行 i 时,以这行为底,计算每一列对应的...原创 2015-05-20 08:58:59 · 202 阅读 · 0 评论 -
Leetcode - House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time...原创 2015-05-20 22:34:27 · 107 阅读 · 0 评论 -
Leetcode - Palindrome Partition
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa...原创 2015-05-21 09:56:20 · 175 阅读 · 0 评论 -
Leetcode - 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 b...原创 2015-04-15 09:40:07 · 103 阅读 · 0 评论 -
Leetcode - Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), ...原创 2015-04-14 10:02:54 · 108 阅读 · 0 评论 -
Leetcode - Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should co...原创 2015-06-06 20:01:27 · 149 阅读 · 0 评论 -
Leetcode - Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false....原创 2015-06-07 11:41:40 · 112 阅读 · 0 评论 -
Leetcode - Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i...原创 2015-07-05 15:52:53 · 121 阅读 · 0 评论 -
Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i...原创 2015-07-05 16:49:11 · 117 阅读 · 0 评论 -
Leetcode - Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 2Inpu...原创 2015-07-29 20:21:33 · 107 阅读 · 0 评论 -
Leetcode - Paint House
There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the ho...原创 2015-08-16 10:48:31 · 147 阅读 · 0 评论 -
Leetcode - Maximum Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 ...原创 2015-08-16 13:33:40 · 207 阅读 · 0 评论 -
Leetcode - Paint House II
There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two ad...原创 2015-08-20 20:37:11 · 115 阅读 · 0 评论 -
Leetcode - Ugly Number II
[分析]暴力的办法就是从1开始检查每个数是否是丑数,发现丑数计数器加1直到找到第n个丑数。这种方法效率低,因为它不管是不是丑数都进行了计算,所以优化方向是仅计算丑数而不在非丑数上耗费时间。易知后面的丑数一定是前面的丑数乘以2或者3或者5得到的,假设现在已经计算出第k个丑数U(k),那么下一个丑数是前面丑数中乘以2、3、5中第一个大于U(k)的数。怎么找呢?我们需要保留已计算的所有丑数,将已知丑...原创 2015-08-24 22:54:57 · 106 阅读 · 0 评论 -
Leetcode - 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 adjacen...原创 2015-04-01 09:06:37 · 93 阅读 · 0 评论 -
Leetcode - Word Break
[题目]Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["lee...原创 2015-04-02 09:48:36 · 123 阅读 · 0 评论 -
Leetcode - Maximum Product Subarray
[题目] Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the large...2015-04-10 09:52:18 · 131 阅读 · 0 评论 -
Leetcode - Unique Binary Search Trees
[题目]Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. [分析] n个节点的BST的结构数等于从1到n依次为root节点对应...原创 2015-04-10 10:00:59 · 128 阅读 · 0 评论 -
Leetcode - 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?[分析] 一维动态规划入门题 publi...原创 2015-04-10 10:04:02 · 102 阅读 · 0 评论 -
Leetcode - Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "cats...原创 2015-04-14 09:59:43 · 138 阅读 · 0 评论 -
Leetcode - Palindrome Partition II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return 1 s...原创 2015-05-21 21:15:11 · 176 阅读 · 0 评论
分享