【LeetCode】-Best Time to Buy and Sell Stock
来源:互联网 发布:手机如何开淘宝店铺 编辑:程序博客网 时间:2024/05/18 00:10
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 len = prices.length;if( len==0 )return 0;int profit=0;int min = prices[0];for( int i=0; i<len; i++ ){if( prices[i]<min ){min = prices[i];}if( prices[i]-min>profit ){profit = prices[i]-min;}}return profit; }}
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
- 25个精美的Jquery Mobile手机网站模板
- 贴片电阻(功率)
- ReportStudio进阶教程(六) - 求交叉表指定维度的和
- 分布式搜索Elasticsearch——创建客户端(三)
- NGUI动态创建UILabel
- 【LeetCode】-Best Time to Buy and Sell Stock
- 创建模式之工厂模式二
- Java计算两日期之间的天数
- iOS 之awakeFromNib 和 viewDidLoad的区别
- MTK_android_如何预置APK(整合MTK回复)
- Cocos2d-x教程(4)-创建动画效果,TexturePacker工具
- Linux命令之basename使用
- C++:利用两个栈实现队列操作
- Web设计原则