摘要: int candy(vector &ratings) { // Note: The Solution object is instantiated only once and is reused by each test case. if(ratings.empty()) return 0; int n = ratings.size(); vector candys(n,1); int next_candy = 2; for(int i=0;i0&&ratings[i]>ratin... 阅读全文
posted @ 2013-10-25 22:25 summer_zhou 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 如何避免多个0的情况。。。。 vector restoreIpAddresses(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. vector res; string tmp; dfs(0,4,s,tmp,res); return res; } void dfs(int curpos,int cnt,string& s, string tmp,vec... 阅读全文
posted @ 2013-10-25 21:09 summer_zhou 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 本质上是动态规划。解法一: //O(m*m*n) int maximalRectangle(vector > &matrix) { if(matrix.empty()||matrix[0].empty()) return 0; int m = matrix.size(); int n = matrix[0].size(); vector> cnt(m,vector(n,0)); //cnt[i][j]表示matrix[i][j]往左边延伸‘1’的最大个数。 i... 阅读全文
posted @ 2013-10-25 20:51 summer_zhou 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 计算 int largestRectangleArea(vector &height) { // Start typing your C/C++ solution below // DO NOT write int main() function stack st; height.push_back(0); //加入0之后,起哨兵的作用,这样即使矩形是递增的,也可以将面积计算出来(会走到else语句) int max_area = 0; int i=0; w... 阅读全文
posted @ 2013-10-25 19:31 summer_zhou 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 好多特殊情况。第二次做还是错了很多次,要好好考虑各种情况。 int numDecodings(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. if(s.empty()||s[0]=='0') return 0; int cnt1 = 1, cnt2 = 1; int cnt = 1; //注意,初始时1. for(int i=1;i='1'&&s... 阅读全文
posted @ 2013-10-25 15:59 summer_zhou 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 三维DP。重复子问题->DP bool isScramble(string s1, string s2) { // Note: The Solution object is instantiated only once and is reused by each test case. if(s1.size()!=s2.size()) return false; if(s1.empty()) return true; int n = s1.size(); vec... 阅读全文
posted @ 2013-10-25 15:30 summer_zhou 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 思路理清楚就好。 ListNode *partition(ListNode *head, int x) { // Note: The Solution object is instantiated only once and is reused by each test case. if(head==NULL) return NULL; ListNode* smallHead,*smallTail,*bigHead,*bigTail,*cur,*next; smallHead = smallTail = big... 阅读全文
posted @ 2013-10-25 14:54 summer_zhou 阅读(130) 评论(0) 推荐(0) 编辑
摘要: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. if(n cnt(32,0); int res = 0; for(int i=0;i>i)&1==1) cnt[i] = (cnt[i]+1)%3; } ... 阅读全文
posted @ 2013-10-25 13:47 summer_zhou 阅读(139) 评论(0) 推荐(0) 编辑
摘要: //recursive ListNode *deleteDuplicates(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!head||!head->next) return head; ListNode* p = head->next; if(head->val == p->val) { while(head... 阅读全文
posted @ 2013-10-25 11:08 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑