上一页 1 2 3 4 5 6 7 8 9 ··· 16 下一页
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode *head; ListNode *p=l1,*q=l2; if(p=... 阅读全文
posted @ 2013-05-29 14:03 代码改变未来 阅读(490) 评论(0) 推荐(0) 编辑
摘要: bug:忘记i>0的判断class Solution {public: void nextPermutation(vector<int> &num) { int i=num.size()-1; while(i>0&&num[i]<=num[i-1]) i--; if(i==0)sort(num.begin(),num.end()); else { int k=num[i-1]; int diff=INT_MAX; int inde... 阅读全文
posted @ 2013-05-28 22:34 代码改变未来 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 用vector代替stackclass Solution {public:vector<string>v1; string simplifyPath(string path) { v1.clear(); string s; string temp; for(int i=0;i<path.size();) { if(path[i]=='/') { int j=i+1; temp=""; ... 阅读全文
posted @ 2013-05-28 21:38 代码改变未来 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 不说了,贴代码class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if(head==NULL)return NULL; ListNode *p=head; int i=1; for(;i<m;i++) p=p->next; for(int j=m;j<n;j++) { ListNode *q=p; for(int k=j;k<n;k++) ... 阅读全文
posted @ 2013-05-28 20:04 代码改变未来 阅读(974) 评论(0) 推荐(0) 编辑
摘要: I不要用排列组合,会导致溢出class Solution {public: vector<vector<int> > generate(int numRows) { vector<int>v1; vector<vector<int> >v; for(int i=0;i<numRows;i++) { v1.clear(); for(int j=0;j<=i;j++) { if(j==0||j==i) ... 阅读全文
posted @ 2013-05-27 20:14 代码改变未来 阅读(153) 评论(0) 推荐(0) 编辑
摘要: I:传统n后问题class Solution {public:vector<string>v1;vector<vector<string>>v;vector<int>x; vector<vector<string> > solveNQueens(int n) { x.clear(); for(int i=0;i<n;i++) x.push_back(0); v.clear(); dfs(0,n); return v; } void dfs(int depth,int n) ... 阅读全文
posted @ 2013-05-27 16:31 代码改变未来 阅读(169) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int minPathSum(vector<vector<int> > &grid) { int m=grid.size(); if(m==0)return 0; int n=grid[0].size(); for(int i=1;i<m;i++) grid[i][0]+=grid[i-1][0]; for(int i=1;i<n;i++) grid[0][i]+=grid[0][i-1]; for(int ... 阅读全文
posted @ 2013-05-27 13:36 代码改变未来 阅读(168) 评论(0) 推荐(0) 编辑
摘要: class Solution {public:vector<int>v1;vector<string>v;int count; string inttostring(int n) { stringstream ss; string str; ss<<n; ss>>str; return str; } vector<string> restoreIpAddresses(string s) { v.clear(); if(s.size()>12)return v... 阅读全文
posted @ 2013-05-26 12:23 代码改变未来 阅读(366) 评论(0) 推荐(0) 编辑
摘要: Iclass Solution {public: ListNode *deleteDuplicates(ListNode *head) { if(head==NULL)return NULL; ListNode *p=head; while(p&&p->next) { ListNode *q=p->next; if(q->val==p->val) { if(q->next) { p->... 阅读全文
posted @ 2013-05-25 21:47 代码改变未来 阅读(161) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public:vector<int>v1;vector<vector<int>>v;int countsum; vector<vector<int> > pathSum(TreeNo 阅读全文
posted @ 2013-05-25 21:34 代码改变未来 阅读(565) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 16 下一页