
DP
文章平均质量分 70
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
Edit Distance (Java)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2015-01-29 11:15:44 · 1091 阅读 · 0 评论 -
Unique Binary Search Trees (Java)
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. 1 3 3 2 1 \原创 2015-01-18 10:42:12 · 393 阅读 · 0 评论 -
Triangle (Java)
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-01-18 16:52:00 · 436 阅读 · 0 评论 -
Longest Valid Parentheses (Java)
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 "()",原创 2015-02-08 08:55:41 · 364 阅读 · 0 评论 -
Regular Expression Matching (Java)
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 st原创 2015-02-07 11:21:57 · 429 阅读 · 0 评论 -
Interleaving String (Java)
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原创 2015-02-08 10:34:20 · 364 阅读 · 0 评论 -
Palindrome Partitioning II (Java)
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原创 2015-02-09 11:59:54 · 366 阅读 · 0 评论 -
Unique Binary Search Trees II (Java)
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-01-21 14:37:05 · 398 阅读 · 0 评论 -
Maximum Product Subarray (Java)
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 largest原创 2015-01-21 13:16:27 · 422 阅读 · 0 评论 -
Maximum Subarray (Java)
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-01-18 11:16:03 · 1014 阅读 · 0 评论 -
Climbing Stairs (Java)
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?Sourcepublic class Solut原创 2014-12-26 16:01:47 · 535 阅读 · 0 评论 -
Best Time to Buy and Sell Stock (Java)
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-01-17 17:19:04 · 273 阅读 · 0 评论 -
Distinct Subsequences (Java)
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-01-29 11:52:18 · 373 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III (Java)
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原创 2015-02-04 16:05:10 · 327 阅读 · 0 评论 -
Scramble String (Java)
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 / \ gr原创 2015-02-04 22:22:32 · 487 阅读 · 0 评论 -
Maximal Rectangle (Java)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.设一个数组表示从第一行开始遍历的当前列的高度,再用largest rectangle in histogram那道题的方法算最大面积。Sourcepubl原创 2015-02-05 10:33:20 · 386 阅读 · 0 评论 -
Decode Ways (Java)
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-01-18 14:07:04 · 359 阅读 · 0 评论 -
Minimum Path Sum (Java)
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-01-18 14:32:22 · 353 阅读 · 0 评论 -
Unique Paths (Java)
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-01-18 14:54:44 · 441 阅读 · 0 评论 -
Unique Paths II (Java)
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原创 2015-01-18 15:18:52 · 453 阅读 · 0 评论 -
Word Break (Java)
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 = ["leet"原创 2015-01-21 17:21:59 · 372 阅读 · 0 评论