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 ...
随机推荐
- [BS-09] UITabBarController简单介绍
iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...
- Android --Search界面样式
Lay_Weight 权重属性的使用 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- VMware ESXi 5.5创建虚拟机
1.用鼠标右键单击连接到的IP地址,在弹出的快捷菜单中选择“新建虚拟机”选项,或者按“Ctrl+N”热键. 2.选择自定义 3.自定义服务器名称,并且名称最好是英文而且名称需要是唯一的. 4.选择本地 ...
- vs2015 使用 visual studio on line 在线版本控制
将visual studio on line 作为一个免费在线版本控制器还是不错的,可以支持5个免费用户共同开发, 以下作为记录,贴在此. 一 申请visual studio on line 账户. ...
- [OpenS-CAD]屏幕坐标转换分析
蓝色为地理坐标系XOY,记为坐标系A:黄色为屏幕坐标系xoy,记为坐标系B.地图的左下角点为(X0,Y0)可很容易的平移到坐标原点.因此这里只考虑地图位于坐标原点的情况,如图二也记为坐标系A. 设地理 ...
- HQL的语言
HQL: 是Hibernate Query Language的缩写 1.HQL查询 特点: 与SQL相似,SQL中的语法基本上都可以直接使用 SQL查询的是表和表中的列而HQL查询的是对象或者对象中的 ...
- iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...
- HTML-移动端如何使用css让百分比布局的弹窗水平和垂直方向上居中
pc端让一个弹窗水平和垂直方向居中,在知道弹窗宽高的情况下很好计算,只需要用如下css即可: #date{ width: 300px; height: 300px; position: absolut ...
- 使用NBU进行oracle异机恢复
windows平台的异机恢复,目录不同 1.异机环境准备安装oracle介质安装nbu客户端在异机主机的host文件中添加nbu server主机和原主机信息 2.恢复spfile文件 C:\> ...
- js - ajax中的get和post说明
转自:http://www.cnblogs.com/hateyoucode/archive/2009/12/09/1620050.html 一.谈Ajax的Get和Post的区别 Get方式: 用 ...