
DP
文章平均质量分 77
dyllanzhou
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-09-25 17:21:19 · 239 阅读 · 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. 1 3 3 2 1 \原创 2015-09-16 17:46:40 · 293 阅读 · 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), des原创 2015-09-24 16:18:55 · 256 阅读 · 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 bo原创 2015-09-24 16:49:47 · 252 阅读 · 0 评论 -
[Leetcode] Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length ofS is 1000, and there exists one unique longest palindromic substring.class Solution {public原创 2015-11-13 16:49:15 · 174 阅读 · 0 评论 -
[Leetcode]Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1,col1) and lower right corner (row2, col2).The above rectangle (with the red bor原创 2015-11-14 16:11:38 · 263 阅读 · 0 评论 -
[Leetcode]Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRang原创 2015-11-23 15:11:08 · 233 阅读 · 0 评论 -
[Leetcode]Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2016-01-18 14:41:11 · 313 阅读 · 0 评论 -
[Leetcode]Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], theref原创 2016-01-30 11:47:16 · 289 阅读 · 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-09-14 12:36:51 · 633 阅读 · 0 评论 -
[Leetcode]Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because12 = 4 + 4 + 4; given n = 13,原创 2015-09-10 18:00:28 · 477 阅读 · 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-09-15 17:28:51 · 539 阅读 · 0 评论 -
[Leetcode] Unique Binary Search Trees II
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-10-16 12:24:57 · 228 阅读 · 0 评论 -
[Leetcode]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,原创 2015-10-22 20:37:54 · 236 阅读 · 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-10-22 19:33:27 · 224 阅读 · 0 评论 -
[Leetcode]Word Break
Given a string s and a dictionary of words dict, determine ifs can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet",原创 2015-11-08 16:30:34 · 328 阅读 · 0 评论 -
[Leetcode]Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example,1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10原创 2015-11-10 23:10:32 · 252 阅读 · 0 评论 -
[Leetcode]Palindrome Partitioning 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-10-25 18:13:55 · 286 阅读 · 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 if原创 2015-10-26 19:54:14 · 367 阅读 · 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原创 2015-09-22 15:40:47 · 268 阅读 · 0 评论 -
[Leetcode]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 is原创 2016-03-09 22:40:57 · 342 阅读 · 0 评论