Leetcode 121. Best Time to Buy and Sell Stock
2016-03-25 21:46
246 查看
question
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.
code
public int maxProfit(int[] prices) { int max = 0; int min = Integer.MAX_VALUE; for (int i : prices) { min = Math.min(min, i); max = Math.max(max, i - min); } return max; }
相关文章推荐
- 解决ubuntu-14-04中Qt设计师窗口部件工具箱中不能拖拽部件的方法
- CCF 画图
- 网易网考题“9和g”
- 巧用ifstream判断文件是否存在
- 探讨Nodejs中的作用域问题。
- linux(centos)搭建SVN服务器
- WPF学习——依赖项属性(3)
- Java设计模式之“工厂方法模式”
- MapReduce处理多个不同的出入文件
- Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)
- ExtJS获取父子、兄弟容器元素方法
- 20145214 《Java程序设计》第4周学习总结
- objective-C学习笔记(九)ARC
- 设置一个虚拟域名使内网其他用户也可以通过虚拟域名访问
- 用shell脚本监控进程是否存在 不存在则启动的实例
- poj3904 Sky Code【容斥原理】
- Ubuntu下编译linux内核,报"mkimage" command not found错的解决
- 无人机矩阵操作系统
- PHP include 和 require 语句
- 在Java中使用Json