Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
applewjg committed Oct 6, 2014
1 parent 93e49c4 commit d9192c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions BestTimetoBuyandSellStock.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Author: Annie Kim, [email protected]
Author: Annie Kim, [email protected] : King, [email protected]
Date: Apr 28, 2013
Update: Oct 07, 2014
Problem: Best Time to Buy and Sell Stock
Difficulty: Easy
Source: http://leetcode.com/onlinejudge#question_121
Expand All @@ -15,13 +16,13 @@
class Solution {
public:
int maxProfit(vector<int> &prices) {
int imin = 0;
int res = 0;
for (int i = 1; i < prices.size(); ++i)
int size = prices.size();
if (prices.empty()) return 0;
int minVal = prices[0], res = 0;
for (int i = 1; i < size; ++i)
{
if (prices[i] < prices[imin])
imin = i;
res = max(res, prices[i] - prices[imin]);
minVal = min(minVal, prices[i]);
res = max(res, prices[i] - minVal);
}
return res;
}
Expand Down
3 changes: 3 additions & 0 deletions BestTimetoBuyandSellStockII.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

class Solution {
public:
int maxProfit(vector<int> &prices) {
return maxProfit_2(prices);
}
int maxProfit_1(vector<int> &prices) {
int res = 0;
int buy_i = -1;
Expand Down
7 changes: 3 additions & 4 deletions BinaryTreeMaximumPathSum.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Author: Annie Kim, [email protected]
Author: Annie Kim, [email protected] : King, [email protected]
Date: Apr 28, 2013
Update: Jul 30, 2013
Update: Oct 07, 2014
Problem: Binary Tree Maximum Path Sum
Difficulty: Easy
Source: http://leetcode.com/onlinejudge#question_124
Expand Down Expand Up @@ -41,8 +41,7 @@ class Solution {
int l = maxPathSumRe(node->left, res);
int r = maxPathSumRe(node->right, res);
int sum = max(node->val, max(l, r) + node->val);
res = max(res, sum);
res = max(res, l + r + node->val);
res = max(res, max(0, l) + max(0, r) + node->val);
return sum;
}
};

0 comments on commit d9192c0

Please sign in to comment.