leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0121.cpp (307B)


0 class Solution {
1 public:
2 int maxProfit(vector<int> &prices) {
3 int mini = prices[0];
4 int profit = 0;
5 for (int i = 1; i < prices.size(); i++) {
6 profit = max(prices[i] - mini, profit);
7 mini = min(prices[i], mini);
8 }
9 return profit;
10 }
11 };