Best Time to Buy and Sell Stock II
来源:互联网 发布:华为盒子软件推荐 编辑:程序博客网 时间:2024/06/05 16:52
Best Time to Buy and Sell Stock II
Total Accepted: 6524 Total Submissions: 18350My SubmissionsSay 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 == 0 || prices.length == 1) return 0; int max = 0; for (int i = 1; i < prices.length; i++) { max += prices[i] - prices[i - 1] > 0 ? prices[i] - prices[i - 1] : 0; } return max; }}
0 0
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- 2014年值得关注的10个开源项目(上)
- Binary Tree Maximum Path Sum
- java实现链表 源码
- Best Time to Buy and Sell Stock
- android 内存泄露总结
- Best Time to Buy and Sell Stock II
- 水晶报表10高级开发版下载及序列号
- WordPress修改文章列表显示摘要
- Best Time to Buy and Sell Stock III
- 02-采用时间戳技术防止重复提交
- A Digit Recognizer——基于HTK实现数字串识别系统
- HTML5开发教程:如何创建一个服务器端脚本?
- 某公司面试题:连续子数组的最大和
- Triangle