121. Best Time to Buy and Sell Stock
来源:互联网 发布:学生电脑必备软件 编辑:程序博客网 时间:2024/05/29 16:59
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.
Subscribe to see which companies asked this question
Show Similar Problems
public class Solution { public int maxProfit(int[] price) { int max =0; if(price.length==0)return max; int least = price[0]; for(int i =1;i<price.length;i++){ if(price[i]<least)least=price[i]; else{ if(price[i]-least>max)max=price[i]-least; } } return max; }}
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- C#向ACCESS数据库插入空值
- JQuery实现选项卡效果
- C#向ACCESS数据库插入空值
- 改变dede图片上传路径(商品-缩略图)去掉/allimg/ymd/
- AspNetPager控件的分页与排序
- 121. Best Time to Buy and Sell Stock
- mysql replace()函数
- AspNetPager控件的分页与排序
- Android 如何监听返回键,弹出一个退出对话框
- 蓝桥杯 入门训练 Fibonacci数列
- Java day07 内部类
- Asp.net错误处理机制
- dede 单页文章放根目录下方法
- 整理