[LeetCode]122 Best Time to Buy and Sell Stock II
来源:互联网 发布:短信接收软件下载 编辑:程序博客网 时间:2024/05/16 08:19
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
public class Solution {public int maxProfit(int[] prices) {
if(prices.length < 2 || prices == null)
return 0;
int sum = 0;
for(int i = 1; i < prices.length; i++) {
if(prices[i] - prices[i - 1] > 0)
sum += prices[i] - prices[i - 1];
}
return sum;
}
}
0 0
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode: Best Time to Buy and Sell Stock II [122]
- [leetcode 122] Best Time to Buy and Sell Stock II
- leetcode-122 Best Time to Buy and Sell Stock II
- leetcode || 122、Best Time to Buy and Sell Stock II
- LeetCode 122: Best Time to Buy and Sell Stock II
- Leetcode# 122 Best Time to Buy and Sell Stock II
- leetcode 122: Best Time to Buy and Sell Stock II
- leetCode #122 Best Time to Buy and Sell Stock II
- leetcode: (122) Best Time to Buy and Sell Stock II
- 122 Best Time to Buy and Sell Stock II [Leetcode]
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- 【LEETCODE】122-Best Time to Buy and Sell Stock II
- [leetcode 122] Best Time to Buy and Sell Stock II
- 【leetcode】【122】Best Time to Buy and Sell Stock II
- 电子版《邓小平文选》的配套考证
- java切割大文件方法
- 如何导出含高程值的标注点
- 【English】二月英语——“一个人”“一群人”
- weka中的各种算法说明
- [LeetCode]122 Best Time to Buy and Sell Stock II
- Android inflate的三种使用方法
- 构造和运行模块
- 防止ssh暴力破解利器fail2ban
- 有关ListIterator接口的add与remove方法探究
- shell脚本系列-正则表达式介绍
- C++ 常见错误总结
- Server.MapPath()
- 欢迎使用CSDN-markdown编辑器