动态规划
文章平均质量分 57
nicaishibiantai
这个作者很懒,什么都没留下…
展开
-
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 cover t原创 2014-09-18 06:30:23 · 385 阅读 · 0 评论 -
Lintcode - Longest common subsequence
Given two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.样例For "ABCD" and "EDCA", the LCS is "A" (or D or C), return 1For "ABCD" and "EACB"原创 2015-02-04 13:05:16 · 1312 阅读 · 0 评论 -
Lintcode - Longest common substring
Given two strings, find the longest common substring.Return the length of it.注意The characters in substring should occur continiously in original string. This is different with subsequnce.原创 2015-02-03 13:23:52 · 1436 阅读 · 0 评论 -
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", ret原创 2014-09-17 12:59:31 · 342 阅读 · 0 评论 -
Distinct Subsequences
public int numDistinct(String S, String T) { int row = S.length(); int col = T.length(); int[][] m = new int[row][col]; for (int i = 0; i < row; i++) {原创 2014-09-02 06:52:38 · 339 阅读 · 0 评论 -
Lintcode - Maximum Subarray II
Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.NoteThe subarray shoul原创 2015-02-08 15:12:28 · 4113 阅读 · 0 评论 -
Lintcode - Maximum Subarray Difference
Given an array with integers.Find two non-overlapping subarrays A and B, which|SUM(A) - SUM(B)| is the largest.Return the largest difference.NoteThe subarray should contain at least on原创 2015-03-20 13:02:48 · 4608 阅读 · 0 评论 -
Lintcode - Backpack II
Given n items with size A[i] and value V[i], and a backpack with size m. What's the maximum value can you put into the backpack?NoteYou cannot divide item into small pieces and the total siz原创 2015-03-17 13:13:10 · 2327 阅读 · 0 评论 -
Lintcode - Maximum Subarray III
Given an array of integers and a number k, find knon-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.NoteThe su原创 2015-03-24 05:21:00 · 4361 阅读 · 1 评论 -
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-04-01 12:52:04 · 638 阅读 · 0 评论 -
Coin change
http://www.fgdsb.com/2015/01/03/coin-change-problem/#moreGiven a set of currency denominations, find the minimum number of coins needed to represent an amount.1234567891011121314转载 2015-04-01 11:22:41 · 413 阅读 · 0 评论 -
Lintcode - Minimum Adjustment Cost
Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array before adjustment is A, the array after adjust原创 2015-02-17 15:39:03 · 3411 阅读 · 0 评论 -
Dungeon Gam
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 p原创 2015-04-28 06:21:23 · 379 阅读 · 0 评论 -
lintcode - kth prime number
Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7.The eligible numbers are like 3, 5, 7, 9, 15 ...ExampleIf k=4, return 9.ChallengeO(n原创 2015-02-01 07:32:09 · 1557 阅读 · 1 评论 -
Palindrome PartioningII
public class Solution { int min; public int minCut(String s) { min = Integer.MAX_VALUE; helper(s, 0); return min < 0 ? 0 : min; } void helper(String s, int cut)原创 2014-09-14 06:24:19 · 646 阅读 · 0 评论 -
Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.和 public int maximalRectangle(char[][] matrix) { int area = 0;原创 2014-09-17 04:48:44 · 427 阅读 · 0 评论 -
Maximum Subarray
Find the contiguous subarray within an array (containing at leastone 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原创 2014-08-11 11:31:28 · 620 阅读 · 0 评论 -
二叉树-Binary tree maximum path sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2014-08-24 12:39:52 · 386 阅读 · 0 评论 -
triangle
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], [6,5原创 2014-08-11 11:31:33 · 320 阅读 · 0 评论 -
两个指针-Trapping Rain
Given n non-negativeintegers representing an elevation map where the width of each baris 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1],r原创 2014-08-11 11:30:41 · 312 阅读 · 0 评论 -
股票买卖
1. 只允许买卖一次股票,求最大利润2. 允许买卖多次3. 只允许买卖最多两次股票1. 买卖一次public class Solution { public intmaxProfit(int[] prices) { // Start typing your Java solution below // DO NOT write main() fu原创 2014-08-11 11:31:26 · 418 阅读 · 0 评论 -
Jump Game
Given an array of non-negative integers, you are initiallypositioned at the first index of the array.Each element in the array represents your maximum jump length atthat position.Determine if yo原创 2014-08-11 11:31:54 · 316 阅读 · 0 评论 -
Minimum path sum
Given a m x n gridfilled with non-negative numbers, find a path from top left tobottom right which minimizes thesum of all numbers along its path.public class Solution { public intminPathSu原创 2014-08-11 11:31:31 · 305 阅读 · 0 评论 -
Word Break
1. 完全递归: public boolean wordBreak(String s, Set dict) { if (s.isEmpty()) { return true; } for(int i = 1; i <= s.length(); i++) { if (dict.contains(原创 2014-09-14 06:58:33 · 396 阅读 · 0 评论 -
Edit Distance
public int minDistance(String word1, String word2) { int[] res = new int[word1.length()+1]; for (int i = 0; i < word1.length()+1; i++) { res[i] = i; }原创 2014-09-14 05:14:39 · 330 阅读 · 0 评论 -
Word Break II
超时 public List wordBreak(String s, Set dict) { List> result = new ArrayList>(); helper(result, new ArrayList(), s, 0, dict); List res = new ArrayList(); for (List li原创 2014-09-14 12:44:46 · 508 阅读 · 0 评论 -
Longest Palindrome Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.原创 2014-09-15 05:54:07 · 385 阅读 · 0 评论 -
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 "()",原创 2014-09-15 07:44:24 · 403 阅读 · 0 评论 -
Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width o原创 2014-09-16 13:33:47 · 395 阅读 · 0 评论 -
Regular Expression
public class Solution { public boolean isMatch(String s, String p) { return helper(s, p, 0, 0); } // pos1 s start, pos2 p start boolean helper(String s, String p, int pos1原创 2014-09-18 05:15:43 · 611 阅读 · 0 评论