上一页 1 2 3 4 5 6 7 8 ··· 16 下一页
摘要: class Solution {public: vector<int> spiralOrder(vector<vector<int> > &matrix) { vector<int>v; int m=matrix.size(); if(m==0)return v; int n=matrix[0].size(); for(int i=0;2*i+1<=m&&2*i+1<=n;i++) { for(int k=i;k<n-i;k++) ... 阅读全文
posted @ 2013-06-05 16:39 代码改变未来 阅读(112) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: bool isValidBST(TreeNode *root) { stack<TreeNode *>s; TreeNode *p=root; int pre=INT_MIN; while(p||!s.empty()) { while(p) { s.push(p); p=p->left; } if(!s.empty()... 阅读全文
posted @ 2013-06-03 16:44 代码改变未来 阅读(213) 评论(0) 推荐(0) 编辑
摘要: class Solution {public:vectorv;int num; int sumNumbers(TreeNode *root) { num=0; v.clear(); sum(root); int sum=0; for(int i=0;ival; if(root->left==NULL&&root->right==NULL) { v.push_back(num); } if(root->lef... 阅读全文
posted @ 2013-06-03 16:21 代码改变未来 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 脑子犯傻了。。class Solution {public: bool isSymmetric(TreeNode *root) { if(root==NULL) return true; return ischeck(root->left,root->right); } bool ischeck(TreeNode *p,TreeNode *q) { if(p==NULL&&q==NULL)return true; if(p==NULL&&q!=NULL)return false; ... 阅读全文
posted @ 2013-06-03 16:10 代码改变未来 阅读(1594) 评论(0) 推荐(0) 编辑
摘要: 超时算法—排序dfs:class Solution {public:string s;string s1;int count; string getPermutation(int n, int k) { s="123456789"; count=0; s1=""; dfs(0,n,k); return s1; } void dfs(int depth,int n,int k) { if(depth==n&&count<=k) { count++... 阅读全文
posted @ 2013-06-02 22:39 代码改变未来 阅读(158) 评论(0) 推荐(0) 编辑
摘要: I一次accept,dfsclass Solution {public:vector<vector<string>>v;vector<string>v1; vector<vector<string>> partition(string s) { v.clear(); if(s.size()==0)return v; v1.clear(); dfs(0,s); return v; } bool ishui(string s) { int i=0,j=s.size()-1;... 阅读全文
posted @ 2013-06-02 18:55 代码改变未来 阅读(200) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int maximalRectangle(vector<vector<char> > &matrix) { if (matrix.empty()) { return 0; } int n = matrix[0].size(); vector<int> H(n); vector<int> L(n); vector<int> R(n, n); int ret = 0; for (int i = 0; i < ma... 阅读全文
posted @ 2013-05-31 22:24 代码改变未来 阅读(953) 评论(0) 推荐(0) 编辑
摘要: Iclass Solution {public: int maxProfit(vector<int> &prices) { if(prices.size()==0||prices.size()==1)return 0; int min=prices[0]; int max=prices[0]; int diff=0; for(int i=1;i<prices.size();i++) { if(prices[i]<min)min=prices[i]; ... 阅读全文
posted @ 2013-05-31 14:37 代码改变未来 阅读(146) 评论(0) 推荐(0) 编辑
摘要: I动态规划,一次性构造,查询。采用回溯法会超时class Solution {public:int grid[100][100]; int uniquePaths(int m, int n) { if(grid[m-1][n-1]==0) construct(); return grid[m-1][n-1]; } void construct() { grid[0][0]=1; for(int i=1;i<100;i++) { grid[i][0]=1; } ... 阅读全文
posted @ 2013-05-29 15:14 代码改变未来 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 回文数字,比较简单class Solution {public: bool isPalindrome(int x) { if(x<0)return false; int y=x; int z=0; while(y>0) { int k=y%10; z=z*10+k; y=y/10; } if(z==x)return true; else return false; }}; 阅读全文
posted @ 2013-05-29 14:34 代码改变未来 阅读(144) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 16 下一页