- 跟我一起刷leetCode算法题9之Best Time to B
- Leetcode PHP题解--D109 122. Best T
- leetcode:122. Best Time to Buy a
- [数组]122. Best Time to Buy and Se
- Leetcode122-Best Time to Buy and
- Leetcode 122. Best Time to Buy a
- LeetCode 122. Best Time to Buy a
- LeetCode 122. Best Time to Buy a
- Leetcode 122. Best Time to Buy a
- leetcode 122. Best Time to Buy a
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Best Time to Buy and Sell Stock II2. Solution
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size() == 0) {
return 0;
}
int profit = 0;
for(int i = 1; i < prices.size(); i++) {
int diff = prices[i] - prices[i - 1];
if( diff > 0) {
profit += diff;
}
}
return profit;
}
};
网友评论