LeetCode题目:Best Time to Buy and Sell Stock
原题地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
解决方法:动态规划,minimun存储的是当前价格中最小的。
class Solution {
public:
int maxProfit(vector<int>& prices) {
int minimum = INT_MAX, ret = , size = prices.size();
for(int i = ; i < size; ++i){
if(prices[i] < minimum)
minimum = prices[i];
int diff = prices[i] - minimum;
if(diff > ret)
ret = diff;
}
return ret;
}
};
LeetCode题目:Best Time to Buy and Sell Stock的更多相关文章
- [LeetCode] 121. 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] 122. Best Time to Buy and Sell Stock II 买卖股票的最佳时间 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] 123. Best Time to Buy and Sell Stock III 买卖股票的最佳时间 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] 188. Best Time to Buy and Sell Stock IV 买卖股票的最佳时间 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] 309. 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 ...
- Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】
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
Best Time to Buy and Sell Stock IV Say you have an array for which the ith element is the price of a ...
- [Leetcode Week6]Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/best-time-to-buy-and ...
- [leetcode]123. 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 ...
随机推荐
- go环境安装
选择想要安装的版本: http://golangtc.com/download tar -zxf go1.8.linux-amd64.tar.gz cp -R go/ /usr/local/ vi / ...
- Leap Motion颠覆操控体验的超精致手势追踪技术【转】
转自:http://www.cnblogs.com/emouse/archive/2013/02/28/2936689.html 先来看两段简介视频: 看了介绍视频后,对如此次超高精度的手势追踪非常好 ...
- Apache开启PHP的伪静态模式
首先,什么是伪静态: 伪静态又名URL重写,是动态的网址看起来像静态的网址.换句话说就是,动态网页通过重写 URL 方法实现去掉动态网页的参数,但在实际的网页目录中并没有必要实现存在重写的页面. 1. ...
- Charles 和 ProxyDroid 抓取Websocket
环境: 1.android 7 及以下 有root权限 (可以用模拟器) 2.proxydroid-2-7-5 (下载: https://proxydroid.en.uptodown.com/andr ...
- laravel按月/时间区间查询数据
public function payRollList($time) { $member_phone = Session::get(phone'); $engineer = Engineer::get ...
- 利用注册表在右键添加VisualCode快捷方式
分为两种配置,第一种是对于文件右键也就是 关联文件 第一步: Win+R 打开运行,输入regedit,打开注册表,找到HKEY_CLASSES_ROOT\*\shell分支,如果没有shell分支, ...
- 使用iSCSI Target创建集中式安全存储(一)
iSCSI 是一种块级别的协议,用于通过TCP/IP网络共享原始存储设备,可以用已经存在的IP和以太网如网卡.交换机.路由器等通过iSCSI协议共享和访问存储.iSCSI target是一种由远程iS ...
- (21)C#VS快捷键
1.移动光标 ctrl+ 右键:按单词移动 home:移动到一行得开头 ,end:移动到一行得末尾 ctrl+home:移动到文本得第一行初始位置,ctrl+end文本最末尾 pageDn:往文件下面 ...
- (3)新概念英语一(11-20)lessons
12 13 14 15 16 17 18无单词 19 20
- [Bzoj5285][洛谷P4424][HNOI/AHOI2018]寻宝游戏(bitset)
P4424 [HNOI/AHOI2018]寻宝游戏 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生 ...