leetcode：122. Best Time to Buy and Sell Stock II（java）解答

Best Time to Buy and Sell Stock II

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 int maxProfit(int[] prices) {
int maxPro = 0;
int length = prices.length - 1;
for (int i = 0; i < length; i++) {
if (prices[i] < prices[i + 1]) {
maxPro += prices[i + 1] - prices[i];
}
}
return maxPro;
}

leetcode-java-121. Best Time to Buy and Sell Stock

• github_34514750
• 2016年06月05日 10:32
• 314

weekly contest 55 Best Time to Buy and Sell Stock with Transaction Fee

• weixin_38739799
• 2017年10月23日 14:21
• 466

用go实现linux命令行

• caijhBlog
• 2017年10月17日 20:26
• 129

Leetcode算法学习日志-714 Best Time to Buy and Sell Stock with Transaction Fee

Leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee 题目原文 Your are given an array o...
• Zarlove
• 2017年10月23日 21:16
• 1344

Leetcode:714. Best Time to Buy and Sell Stock with Transaction Fee

DescriptionYour are given an array of integers prices, for which the i-th element is the price of a ...
• csdn_cinderella
• 2017年12月13日 14:02
• 48

LeetCode题解系列--714. Best Time to Buy and Sell Stock with Transaction Fee

• bowen_wu_sysu
• 2017年12月13日 16:39
• 62

714-

Best Time to Buy and Sell Stock with Transaction Fee Your are given an array of integers prices, fo...
• hefenglian
• 2017年10月22日 12:11
• 248

714. Best Time to Buy and Sell Stock with Transaction Fee

Your are given an array of integers prices, for which the i-th element is the price of a given stock...
• xdhc304
• 2018年01月27日 16:32
• 37

714. Best Time to Buy and Sell Stock with Transaction Fee

Your are given an array of integers prices, for which the i-th element is the price of a given stoc...
• zjucor
• 2017年10月23日 10:12
• 728

【12月19日】LeetCode刷题日志（三）：Best Time to Buy and Sell Stock with Transaction Fee

• Moon_treee
• 2017年12月19日 15:22
• 47

举报原因： 您举报文章：leetcode：122. Best Time to Buy and Sell Stock II（java）解答 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)