best-time-to-buy-and-sell-stock-ii 1.0.0
Best Time to Buy and Sell Stock II
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

int maxProfit (vector< int > &prices)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ maxProfit()

int Solution::maxProfit ( vector< int > &  prices)
inline

Definition at line 8 of file main.cpp.

9 {
10 int buy_price = prices[0];
11 int profit = 0;
12 for (int price: prices)
13 {
14 if (price > buy_price)
15 {
16 profit += price - buy_price;
17 buy_price = price;
18 }
19 if (price < buy_price)
20 {
21 buy_price = price;
22 }
23 }
24 return profit;
25 }

Referenced by main().


The documentation for this class was generated from the following file: