摘要: http://oj.leetcode.com/problems/binary-tree-preorder-traversal/!看题上来就递归 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 p... 阅读全文
posted @ 2013-11-15 15:21 沙茶面 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 斐波那契数列:http://zh.wikipedia.org/wiki/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97卡塔兰数:http://en.wikipedia.org/wiki/Catalan_number完美数:http://zh.wikipedia.org/wiki/%E5%AE%8C%E7%BE%8E%E6%95%B0 阅读全文
posted @ 2013-11-15 13:49 沙茶面 阅读(133) 评论(0) 推荐(0) 编辑
摘要: #二分我好乱 1 class Solution { 2 public: 3 int searchInsert(int A[], int n, int target) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if(n == 0) return n; 7 if(target A[n-1]) return... 阅读全文
posted @ 2013-11-14 17:51 沙茶面 阅读(135) 评论(0) 推荐(0) 编辑
摘要: =看完别人的代码,就无限接近于认为自己是沙茶。大家的思路怎么这么简洁,以至于我能看懂,我估计我的代码别人都看不懂。 1 void flatten(TreeNode *root) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 TreeNode*tmp; 5 flattenpiece(root,tmp); 6 ... 阅读全文
posted @ 2013-11-14 17:41 沙茶面 阅读(135) 评论(0) 推荐(0) 编辑
摘要: !由于题意是两次交易,而且这两次买卖不能再时间上重叠,是两个独立的问题,联想到分而治之的策略,将{0,1,...,i,...,n-1,n}的问题拆分为求{0,1,..,i}和{i+1,...,n-1,n}两个子问题,而这两个子问题又刚好是Best Time to Buy and Sell Stock I的解题思路。 1 int maxProfit(vector &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instan... 阅读全文
posted @ 2013-11-13 01:09 沙茶面 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 符号 含义 !解题思路=感悟#犯错 阅读全文
posted @ 2013-11-13 00:04 沙茶面 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1 int maxProfit(vector &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 int i; 5 int res=0; 6 if(prices.size() prices[i-1])13 res+=(prices[i]-prices[... 阅读全文
posted @ 2013-11-13 00:00 沙茶面 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Plan A: 1 int maxProfit(vector &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 int i; 5 int res=0; 6 if(prices.size() == 0 || prices.size()==1) 7 { 8 ... 阅读全文
posted @ 2013-11-12 23:53 沙茶面 阅读(407) 评论(0) 推荐(0) 编辑
摘要: this is a test 阅读全文
posted @ 2013-11-12 23:28 沙茶面 阅读(126) 评论(1) 推荐(0) 编辑