Skip to content

add 122 cpp version(4ms) #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add 122 cpp version(4ms)
  • Loading branch information
zouwx2cs committed Oct 17, 2018
commit 36b4fc72f5328b83c2c6162b3e44a2c4092f8e87
15 changes: 15 additions & 0 deletions solution/122.Best Time to Buy and Sell Stock II/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public:
int maxProfit(vector<int>& prices)
{
if (0 == prices.size())
return 0 ;
int M = 0 ;
for (int i = 1; i < prices.size(); ++i)
{
int d = prices[i] - prices[i-1] ;
if (d > 0)
M += d ;
}
return M ;
}
};