Best Time to Buy and Sell Stock
class Solution {
public:
int maxProfit(vector<int>& prices) {
//eg: 5 6 2 3 1 4;
// 记录i之前最小的元素;
int min = INT_MAX;
int pro = ;
int n=prices.size();
for(int i=;i<n;i++){
if(prices[i]-min >pro) pro=prices[i]-min;
else if(prices[i] < min) min = prices[i];
}
return pro;
}
};
Best Time to Buy and Sell Stock的更多相关文章
- [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock III 买股票的最佳时间之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LintCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- LeetCode——Best Time to Buy and Sell Stock II (股票买卖时机问题2)
问题: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- 123. Best Time to Buy and Sell Stock (三) leetcode解题笔记
123. Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the pric ...
- 122. Best Time to Buy and Sell Stock(二) leetcode解题笔记
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...
随机推荐
- 端口转发后执行putty连接------------------》VirtualBox+ubuntu_server
login as: fleam fleam@127.0.0.1's password: Welcome to Ubuntu LTS (GNU/Linux --generic i686) * Docum ...
- Power-BI绿色开发平台
- JRE和JDK的区别
1. 定义 JRE(Java Runtime Enviroment)是Java的运行环境.面向Java程序的使用者,而不是开发者.如果你仅下载并安装了JRE,那么你的系统只能运行Java程序.JRE是 ...
- 理解JDBC和JNDI
下面的英文是我找过来的,因为是英文所以不敢翻译出来误导别人,但是它描述的确实恰到好处,比所谓网上的JNDI和JDBC云云的解释要精辟很多,如果遇到不认识的单词,用有道吧~~:) The Java Na ...
- Socket 编程
- Java知多少(19)访问修饰符(访问控制符)
Java 通过修饰符来控制类.属性和方法的访问权限和其他功能,通常放在语句的最前端.例如: 1 public class className { 2 // body of class 3 } 4 pr ...
- 【Origin】羡旁人
-道行至一桥畔,微风轻抚,观河岸杨柳柳枝空舞,看满路车辆畅行无阻,虽羡,然各有归途. 小河岸,棵棵杨柳,柳枝随风摆; 大路上,盏盏绿灯,一路往北开. 横批: 可惜不是我 -作于二零一六年三月二十二日
- 常见的appbug(转)
移动App Bug的影响是用户体验差.App的商店评级下降.用户换用竞争对手的App,声誉和信誉损失.最后销售量减少,如果它是一个付费App的话. 移动App测试与传统台式机测试相比有一定的复杂性.这 ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- oracle表分区
注:新建分区表前要先准备好要用的表空间 一. oracle分区类型: 范围分区(Range分区) 列表分区(List分区) 散列分区(Hash分区) 组合分区(Composite Partitioni ...