上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 31 下一页
  2012年12月30日
摘要: struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: TreeNode *buildTree(vector<int> &pre, int preStart, vector<int> &in, int inStart, int len){ if (preStart<0 || preStart+len>pre.size() || 阅读全文
posted @ 2012-12-30 16:55 kkmm 阅读(243) 评论(0) 推荐(0) 编辑
摘要: struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: TreeNode *buildTree(vector<int> &in, int inStart, vector<int> &post, int postStart, int len){ if (inStart<0 || inStart+len>in.size() || 阅读全文
posted @ 2012-12-30 16:50 kkmm 阅读(189) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <stack>using namespace std;struct Node{ int data; Node *next; Node(int d) : data(d) {}};int label = 0;//思路:设两个指针,left和right,首先将right走到头,交换left和right,然后每return一次,right自动向左一次,left手动向右走一次。void Reverse(Node *&left, Node *right){ if (!left || !right) return;... 阅读全文
posted @ 2012-12-30 16:29 kkmm 阅读(499) 评论(0) 推荐(0) 编辑
  2012年12月21日
摘要: 使用深度优先搜索解决。#include <iostream>#include <string>#include <vector>using namespace std;class Solution {public: vector<vector<int> > combinationSum(vector<int> &candidates, int target) { vector<int> tmpresult; tmpresult.clear(); combinationSumCore(candidates 阅读全文
posted @ 2012-12-21 16:49 kkmm 阅读(264) 评论(0) 推荐(0) 编辑
  2012年12月19日
摘要: #include <iostream>#include <string>using namespace std;struct TreeNode{ int data; TreeNode *lchild; TreeNode *rchild;};TreeNode *findMin(TreeNode *&root){ while (root->lchild) root = root->lchild; return root;}void DeleteNode(TreeNode *root, int x){ if (!root) return... 阅读全文
posted @ 2012-12-19 22:53 kkmm 阅读(347) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>using namespace std;class Solution {public:/*解释:首先,因为能买2次(第一次的卖可以和第二次的买在同一时间),但第二次的买不能在第一次的卖左边。所以维护2个表,f1和f2,size都和prices一样大。意义:f1[i]表示 -- 截止到i下标为止,左边所做交易能够达到最大profit;f2[i]表示 -- 截止到i下标为止,右边所做交易能够达到最大profit;那么,对于f1 + f2,寻求最大即可。*/ int maxProfit(vector< 阅读全文
posted @ 2012-12-19 21:13 kkmm 阅读(4697) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>using namespace std;//总体思路,每当有一个上升趋势,就要抓住它//那么维护2个迭代器,left和right,left指向阶段性最低(靠左),right指向阶段性最高(靠右)//需要注意的是迭代器在使用的过程中不要超出了范围,例如下面注释部分特别需要注意class Solution {public: int maxProfit(vector<int> &prices) { vector<int>::const_iterator left = pri 阅读全文
posted @ 2012-12-19 21:11 kkmm 阅读(263) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>#include <stack>using namespace std;//简单的DP算法class Solution {public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int size = prices.size(); if (!size) r... 阅读全文
posted @ 2012-12-19 21:10 kkmm 阅读(169) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: vector<vector<int> > levelOrderBottom( 阅读全文
posted @ 2012-12-19 00:00 kkmm 阅读(195) 评论(0) 推荐(0) 编辑
  2012年12月18日
摘要: #include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: vector<vector<int> > levelOrder(TreeNo 阅读全文
posted @ 2012-12-18 23:59 kkmm 阅读(233) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 31 下一页