上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 20 下一页
摘要: vector generateParenthesis(int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int left_cnt = n,right_cnt = n; vector res; dfs(left_cnt,right_cnt,"",res); return res; } void dfs(int left_cnt,int right_cnt,s... 阅读全文
posted @ 2013-10-06 14:22 summer_zhou 阅读(119) 评论(0) 推荐(0) 编辑
摘要: ListNode *removeNthFromEnd(ListNode *head, int n) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!head||nnext; while(fast->next) { fast = fast->next; prev = slow; slow = slow->next; ... 阅读全文
posted @ 2013-10-06 14:09 summer_zhou 阅读(131) 评论(0) 推荐(0) 编辑
摘要: int uniquePathsWithObstacles(vector > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(obstacleGrid[0][0]==1) return 0; int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); vector> dp(m,... 阅读全文
posted @ 2013-10-06 13:48 summer_zhou 阅读(125) 评论(0) 推荐(0) 编辑
摘要: bool isPalindrome(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. if(x=10) { div*=10; } while(x) { int a = x/div; int b = x%10; if(a!=b) re... 阅读全文
posted @ 2013-10-06 09:48 summer_zhou 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 考虑越界的问题 int reverse(int x) { // Note: The Solution object is instantiated only once and is reused by each test case. bool bNega = false; if(xINT_MAX) return (bNega?INT_MIN:INT_MAX); else return (bNega?-res:res); } 阅读全文
posted @ 2013-10-06 09:25 summer_zhou 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Q:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.A: DP int minPathSum(vector > &grid) { // Note: The Solution object is instantia... 阅读全文
posted @ 2013-10-05 23:06 summer_zhou 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 递归。虽然有很多重叠的子问题,但是用DP的话很难表示。。所以用递归也ok,数据集也能过 vector generateTrees(int n) { return construct(1,n); } vector construct(int start,int end) { vector res; if(start>end) { res.push_back(NULL); return res; } for(int i... 阅读全文
posted @ 2013-10-05 17:03 summer_zhou 阅读(131) 评论(0) 推荐(0) 编辑
摘要: void swap(int* a, int* b){ int tmp = *a; *a = *b; *b = tmp;}class Solution {public: int removeDuplicates(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int cnt = 0; int cur = -1,i; for(i=0;i<n;i++) ... 阅读全文
posted @ 2013-10-05 16:47 summer_zhou 阅读(120) 评论(0) 推荐(0) 编辑
摘要: void swap(int* a, int* b){ int tmp = *a; *a = *b; *b = tmp;}class Solution {public: int removeDuplicates(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int cur = -1,i; for(i=0;i<n;i++) { if... 阅读全文
posted @ 2013-10-05 16:41 summer_zhou 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Catalan number.但是注意Catalan number n==0时, h(n) = 1;而题目中n==0时,cnt =0 int numTrees(int n) { // Note: The Solution object is instantiated only once and is reused by each test case. //Catanlan number //h(n)=h(n-1)*(4*n-2)/(n+1) = C(2n,n)/(n+1) = c(2n,n)-c(2n,n+1)(n=0,1,2,...) ... 阅读全文
posted @ 2013-10-05 16:29 summer_zhou 阅读(139) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 20 下一页