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相关推荐

  1. LeetCode 309. Best Time to Buy and Sell Stock with Cooldown--Java解法-卖股票系列题目

    此文首发于我的Jekyll博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址: ...

  2. LeetCode 123. Best Time to Buy and Sell Stock III--Python解法--动态规划--数学题

    此文首发于我的个人博客:zhang0peter的个人博客 LeetCode题解文章分类:LeetCode题解文章集合 LeetCode 所有题目总结:LeetCode 所有题目总结 题目地址:Best ...

  3. 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 ...

  4. [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 ...

  5. 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 ...

  6. 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/ 题解 经典的 暴力递归 - ...

  7. 【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 ...

  8. [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 ...

  9. [leetcode]_Best Time to Buy and Sell Stock I II

    一个系列三道题,我都不会做,google之答案.过了两道,第三道看不懂,放置,稍后继续. 一.Best Time to Buy and Sell Stock I 题目:一个数组表示一支股票的价格变换. ...

  10. 【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 ...

最新文章

  1. 关于自注意力机制的思考
  2. jquery事件重复绑定的几种解决方法 (二)
  3. vue项目实现列表页-详情页返回不刷新,再点其他菜单项返回刷新的需求
  4. 全球大学文凭“含金量”排名出炉:“北清复”名列30强
  5. [jquery]为jQuery.ajax添加onprogress事件
  6. vim剪切指定行_10 分钟上手 Vim,常用命令大盘点
  7. 信用评分系统运行原理下篇
  8. 苹果iPhone发布13周年:累计销量近20亿部
  9. 侏儒排序算法原理与Python实现
  10. jQuery中Ajax+Spring MVC实现跨域请求
  11. 【转】Quartz.NET快速入门指南
  12. 2021年第十八届五一数学建模竞赛题目 C题 数据驱动的异常检测与预警问题 解题论文完整版
  13. 问卷设计:量表到底是要用5级还是6级?
  14. 联想笔记本小新V2000怎么进BIOS设置
  15. oracle lpad函数有中文,oracle lpad函数和rpad函数
  16. kafka消息堆积及分区不均匀的解决方案
  17. HTML Table设置无边框、无分割线
  18. PLC若想实现以太网口无线通讯,需要具备哪些条件?
  19. CGAL 三维三角剖分
  20. PLSQL 与 PLPGSQL

热门文章

  1. ML 04、模型评估与模型选择
  2. 支持向量机原理(一)线性支持向量机
  3. 【总结整理】JQuery基础学习---DOM篇
  4. lua 代码加密方案
  5. Shiro快速入门 —— 9.freemaker使用shiro标签
  6. java ListString 转换成带逗号的字符串
  7. Delphi_04_Delphi_Object_Pascal_基本语法_02
  8. JavaScript Object对象
  9. Windows API获取系统配置文件的配置参数
  10. QQ空间的“神奇”图片