![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DP
zhaobaoxue
这个作者很懒,什么都没留下…
展开
-
Generate Parentheses
class Solution {public: vector generateParenthesis(int n) { vector result; string path; dfs(n, 0, 0, path, result); return result; } void dfs(int n, int l,转载 2014-04-07 17:18:03 · 403 阅读 · 0 评论 -
Spiral Matrix
注意细节。class Solution {public: vector spiralOrder(vector > &matrix) { vector result; int row = matrix.size(); if(row == 0) return result; int col = matrix原创 2014-09-10 20:22:49 · 323 阅读 · 0 评论 -
Palindrome Number
和Reverse Integer类似,按位处理,而不要转换成String。原创 2014-09-10 12:08:11 · 329 阅读 · 0 评论 -
Edit Distance
DP+滚动数组。注意长度原创 2014-09-09 19:44:31 · 379 阅读 · 0 评论 -
Distinct Subsequences
题目描述:Given a string S and a string T, count the number of distinct subsequences ofT inS.A subsequence of a string is a new string which is formed from the original string by deleting some转载 2014-09-09 21:08:26 · 431 阅读 · 0 评论 -
Word Break
DPclass Solution {public: bool wordBreak(string s, unordered_set &dict) { const int n = s.size(); if(n == 0) return true; vector f(n+1, false); f[0] = true;原创 2014-09-09 21:48:55 · 342 阅读 · 0 评论 -
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 the total nu原创 2014-04-15 11:57:15 · 368 阅读 · 0 评论 -
Maximal Rectangle
三种方法,第一种参考 http://blog.csdn.net/fightforyourdream/article/details/17711893Time O(n^3),原创 2014-09-09 15:43:11 · 400 阅读 · 0 评论 -
Minimum Path Sum
DP + 滚动数组,注意首行和首列特殊处理。原创 2014-09-09 18:07:32 · 346 阅读 · 0 评论 -
Scramble String
DP, Time O(n^4), Space O(n^3)。原创 2014-09-09 17:55:51 · 347 阅读 · 0 评论 -
Interleaving String
1. 2维 DP。class Solution {public: bool isInterleave(string s1, string s2, string s3) { const int n1 = s1.size(); const int n2 = s2.size(); const int n3 = s3.size();原创 2014-09-09 16:46:22 · 337 阅读 · 0 评论 -
Palindrome Partitioning II
DP.先利用DP计算每个substr是否原创 2014-09-09 11:44:52 · 322 阅读 · 0 评论 -
Reverse Integer
注意处理overflow和negative的问题。class Solution {public: int reverse(int x) { bool positive = (x>=0); x = abs(x); int result = 0; for(; x; x/=10)原创 2014-09-10 11:54:03 · 315 阅读 · 0 评论