leetcode:Best Time to Buy and Sell Stock
来源:互联网 发布:赛亚人遮脸的软件 编辑:程序博客网 时间:2024/04/27 13:41
给出一个一维的数组prices[],prices[i]表示第i个点上股票的价格,
现在给出一个事务交易,买进后卖出,请问可最大获利多少
public class Solution { public int maxProfit(int[] prices) { if(prices.length <= 1){ return 0; } int maxp = 0; int low = prices[0]; for(int i = 1; i < prices.length; ++i){ int t = prices[i] - low; if(t > maxp){ maxp = t; } if(low > prices[i]){ low = prices[i]; } } return maxp; }}
0 0
- 【LeetCode】Best Time to Buy and Sell Stock & Best Time to Buy and Sell Stock
- [LeetCode] [LeetCode]Best Time to Buy and Sell Stock
- 【LeetCode with Python】 Best Time to Buy and Sell Stock
- [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
- 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 a stock I
- 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] Best Time to Buy and Sell Stock III
- LeetCode : Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock
- leetcode 16: Best Time to Buy and Sell Stock III
- LeetCode Best Time to Buy and Sell Stock
- spring缓存机制-根据condition加入缓存(三)
- Android Wear Preview - Get Started With Developer Preview
- HDOJ 2037 今年暑假不AC
- MySQL存储引擎
- 2.Objective-C语法快速参考
- leetcode:Best Time to Buy and Sell Stock
- 今日作息及食谱(6.15)
- IOS学习路线图
- 拷贝构造函数(浅拷贝、深拷贝)
- What is the difference between JRE,JVM and JDK?
- spring缓存机制-@CachePut的用法(四)
- 组合模式(Composite)
- 关于java环境变量中javac和java -version命令不能识别
- Mysql入门之路一