摘要: class Solution {public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if( prices.size() < 2 ) return 0; int result = 0; int min = 0,i; for(i = 1; i< prices.size(); i++) { ... 阅读全文
posted @ 2013-04-10 23:18 冰点猎手 阅读(118) 评论(0) 推荐(0)
摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */// 三种遍历的递归实现void preOrder(TreeNode * root){ if(NULL == root ) return ; visit(root->val); preOrder(root->left); pr... 阅读全文
posted @ 2013-04-10 20:12 冰点猎手 阅读(174) 评论(0) 推荐(0)
摘要: Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 分析: 对于当前的股票价格收益最大是当前价格减去之前股票的最低价,所以需要一个指针来保存当前股票前面的最低价。 阅读全文
posted @ 2013-04-10 11:00 冰点猎手 阅读(149) 评论(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: int getMax(TreeNode *root){ if(root == NULL) return 0; int left = getMax(roo... 阅读全文
posted @ 2013-04-10 10:20 冰点猎手 阅读(135) 评论(0) 推荐(0)
摘要: A过了,但是是那种BT解法,明天再想个正解/** * 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<vector<int> > levelOrderBottom(TreeNode *root) { // Start t... 阅读全文
posted @ 2013-04-10 00:18 冰点猎手 阅读(128) 评论(0) 推荐(0)