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 = 0;int n=prices.size();for(int i=0;i<n;i++){if(prices[i]-min >pro) pro=prices[i]-min;else if(prices[i] < min) min = prices[i];}return pro;} };
转载于:https://www.cnblogs.com/julie-yang/p/4671485.html
Best Time to Buy and Sell Stock相关推荐
- LeetCode 309. Best Time to Buy and Sell Stock with Cooldown--Java解法-卖股票系列题目
此文首发于我的Jekyll博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址: ...
- LeetCode 123. Best Time to Buy and Sell Stock III--Python解法--动态规划--数学题
此文首发于我的个人博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址:Best ...
- LeetCode 122. Best Time to Buy and Sell Stock II--贪心--Java,C++,Python解法
题目地址:Best Time to Buy and Sell Stock II - LeetCode Say you have an array for which the ith element i ...
- [LeetCOde][Java] 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 a ...
- LeetCode Best Time to Buy and Sell Stock II
原题链接在这里:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 题目: Say you have an array ...
- leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee | 714. 买卖股票的佳最时机含手续费(递归->傻缓存->dp)
题目 https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/ 题解 经典的 暴力递归 - ...
- 【LeetCode】 Best Time to Buy and Sell Stock I II III IV 解题报告
原文地址:http://liangjiabin.com/blog/2015/04/leetcode-best-time-to-buy-and-sell-stock.html Best Time to ...
- [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 ...
- [leetcode]_Best Time to Buy and Sell Stock I II
一个系列三道题,我都不会做,google之答案.过了两道,第三道看不懂,放置,稍后继续. 一.Best Time to Buy and Sell Stock I 题目:一个数组表示一支股票的价格变换. ...
- 【DP + 卖股票】LeetCode 714. Best Time to Buy and Sell Stock with Transaction Fee
LeetCode 714. Best Time to Buy and Sell Stock with Transaction Fee Solution1: 参考网址:http://www.cnblog ...
最新文章
- 关于自注意力机制的思考
- jquery事件重复绑定的几种解决方法 (二)
- vue项目实现列表页-详情页返回不刷新,再点其他菜单项返回刷新的需求
- 全球大学文凭“含金量”排名出炉:“北清复”名列30强
- [jquery]为jQuery.ajax添加onprogress事件
- vim剪切指定行_10 分钟上手 Vim,常用命令大盘点
- 信用评分系统运行原理下篇
- 苹果iPhone发布13周年:累计销量近20亿部
- 侏儒排序算法原理与Python实现
- jQuery中Ajax+Spring MVC实现跨域请求
- 【转】Quartz.NET快速入门指南
- 2021年第十八届五一数学建模竞赛题目 C题 数据驱动的异常检测与预警问题 解题论文完整版
- 问卷设计:量表到底是要用5级还是6级?
- 联想笔记本小新V2000怎么进BIOS设置
- oracle lpad函数有中文,oracle lpad函数和rpad函数
- kafka消息堆积及分区不均匀的解决方案
- HTML Table设置无边框、无分割线
- PLC若想实现以太网口无线通讯,需要具备哪些条件?
- CGAL 三维三角剖分
- PLSQL 与 PLPGSQL