Definition at line 5 of file main.cpp.
◆ 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: