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)


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