LeetCode题解:Best Time to Buy and Sell Stock
来源:互联网 发布:网络繁忙请稍后再试 编辑:程序博客网 时间:2024/06/05 10:19
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
题意:找出买卖股票的最佳时机,只能完成一单交易
解决思路:……
代码:
public class Solution { public int maxProfit(int[] prices) { int maxCur = 0, maxSoFar = 0; for(int i = 1; i < prices.length; i++) { maxCur = Math.max(0, maxCur += prices[i] - prices[i-1]); maxSoFar = Math.max(maxCur, maxSoFar); } return maxSoFar; }}
0 0
- LeetCode - Best Time to Buy and Sell Stock III 题解
- LeetCode题解-Best Time to Buy and Sell Stock
- LeetCode题解-Best Time to Buy and Sell Stock II
- LeetCode题解-Best Time to Buy and Sell Stock III
- LeetCode题解:Best Time to Buy and Sell Stock
- LeetCode题解:Best Time to Buy and Sell Stock II
- LeetCode题解:121. Best Time to Buy and Sell Stock
- Leetcode题解 121. Best Time to Buy and Sell Stock
- LeetCode 121 Best Time to Buy and Sell Stock题解
- 【LeetCode题解】121. Best Time to Buy and Sell Stock
- LeetCode题解:121. Best Time to Buy and Sell Stock
- LeetCode 121. Best Time to Buy and Sell Stock & 122. Best Time to Buy and Sell Stock II题解
- 【LeetCode】Best Time to Buy and Sell Stock & Best Time to Buy and Sell Stock
- LeetCode122. Best Time to Buy and Sell Stock II题解
- LeetCode121. Best Time to Buy and Sell Stock题解
- Best Time to Buy and Sell Stock系列问题题解
- Lintcode149 Best Time to Buy and Sell Stock solution 题解
- 【动态规划】Leetcode编程题解:121. Best Time to Buy and Sell Stock Add to List
- 下载微软虚拟学院视频字幕,解决本地播放没有字幕
- TCP/IP详解卷1 读书笔记:第七章 Ping程序
- LeetCode题解:Triangle
- Java学习笔记----封装和private关键字
- repo 获取Android源码
- LeetCode题解:Best Time to Buy and Sell Stock
- 第三周—项目3 求集合并集
- Swift学习(二)
- C++控制台下的贪吃蛇
- C#学习之路 , 学习笔记 2.4 转义字符 和 @控制符
- 小坑+1 runAction 顺序
- LeetCode题解:Best Time to Buy and Sell Stock II
- OC 打印结构体的内容
- 编写程序,要求输入年月日,输出该日是本年中的第几天