LeetCode 122 Best Time to Buy and Sell Stock II
2014-06-21 10:00
363 查看
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==0||prices.length==1) return 0; int result=0; for(int i=1;i<prices.length;i++){ if(prices[i]>prices[i-1]) result+=(prices[i]-prices[i-1]); } return result; } }
相关文章推荐
- LeetCode(122) Best Time to Buy and Sell Stock II (Java)
- 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, Medium] 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]
- 122 Best Time to Buy and Sell Stock II [Leetcode]
- leetcode 122: Best Time to Buy and Sell Stock II
- LeetCode122:Best Time to Buy and Sell Stock II
- Leetcode#122 Best Time to Buy and Sell Stock II
- LeetCode122:Best Time to Buy and Sell Stock II
- [Leetcode 51] 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_question_122 Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- [LeetCode 122] - 买入与卖出股票的最佳时机II(Best Time to Buy and Sell Stock II)