Skip to content

Commit 36b4fc7

Browse files
author
zouwx2cs
committed
add 122 cpp version(4ms)
1 parent 03cf40e commit 36b4fc7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public:
2+
int maxProfit(vector<int>& prices)
3+
{
4+
if (0 == prices.size())
5+
return 0 ;
6+
int M = 0 ;
7+
for (int i = 1; i < prices.size(); ++i)
8+
{
9+
int d = prices[i] - prices[i-1] ;
10+
if (d > 0)
11+
M += d ;
12+
}
13+
return M ;
14+
}
15+
};

0 commit comments

Comments
 (0)