DP
文章平均质量分 71
smallfish_yy
人最幸福的事之一就是把爱好变成自己的工作。
展开
-
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?Analysis: It's a DP problem. F原创 2014-01-13 14:13:19 · 329 阅读 · 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 = "原创 2014-02-10 03:41:26 · 395 阅读 · 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 = ["leet"原创 2014-02-10 03:28:54 · 399 阅读 · 0 评论 -
[Leetcode] - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2014-03-07 07:41:05 · 532 阅读 · 0 评论 -
最长递增子序列 O(NlogN)算法
今天学习了求最长递增子序列这个题的O(NlogN)的解法。记录一下大概的思路,要不然过一段时间又该忘了。基本思路就是维护一个数组,假设为DP。DP[i]所记录的是,在原始数组的所有长度为i+1的单调递增子序列中,结尾处元素的最小值。同时还需要一个变量len,用来记录当前所遇到的所有元素能组成的递增子序列的最大长度。分析后可以发现,DP这个数组一定是有序的,所以每次对它的更新,可以用二分法来实现转载 2014-03-06 07:35:27 · 1280 阅读 · 0 评论 -
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 \原创 2013-12-23 15:04:28 · 400 阅读 · 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], [原创 2014-02-08 15:17:49 · 355 阅读 · 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原创 2014-02-04 14:33:56 · 343 阅读 · 0 评论 -
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原创 2014-02-04 13:52:04 · 329 阅读 · 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原创 2014-01-20 08:31:32 · 330 阅读 · 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", ret原创 2014-01-28 13:25:53 · 382 阅读 · 0 评论