best-time-to-buy-and-sell-stock Java code
来源:互联网 发布:linux黑客帝国代码雨 编辑:程序博客网 时间:2024/05/17 22:55
Say you have an array for which the i th 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.
import java.util.*;public class Solution { public int maxProfit(int[] prices) { if(prices.length<2){ return 0; } int maxProfit=0; int temp = prices[0]; for(int i=1; i<prices.length; i++){ temp = Math.min(temp, prices[i]); maxProfit = Math.max(maxProfit, prices[i]-temp); } return maxProfit; }}
阅读全文
0 0
- best-time-to-buy-and-sell-stock Java code
- best-time-to-buy-and-sell-stock Java code
- best-time-to-buy-and-sell-stock Java code
- CODE 12: Best Time to Buy and Sell Stock
- CODE 11: Best Time to Buy and Sell Stock II
- CODE 10: Best Time to Buy and Sell Stock III
- [leet code] Best Time to Buy and Sell Stock II
- [leet code] 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
- JavaMail创建邮件和发送邮件
- 10.12java
- 嵌入式linux内核启动过程简明描述
- EPOLL
- 一周小程序【资讯教程Demo】更新
- best-time-to-buy-and-sell-stock Java code
- python+selenium搜狗微信主页抓取
- AngularJS验证两次密码是否相同
- Httpclient 参数
- 第一次作业
- 解决异常报错org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible问题
- sql时间截取转换大全
- 笔记4——C 字符串处理函数
- OpenCV之Mat矩阵和数组的运算