原题地址: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的更多相关文章

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

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

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

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

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

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

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

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

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

随机推荐

  1. 联合权值(NOIP2014)奇特的模拟。。

    原题传送门 这道题瞄了一眼还以为是SPFA最短路. 后面发现距离为2.. 好像可以枚举中间点来着? 时间效率O(n*(2n-2))≍O(n^2) BOOM!(PS:9018上过了,说明数据太水了..) ...

  2. eclipse 导出burpsuite插件包含第三方lib包

    第一步:右键项目点击export: 2.选择Runable JAR file: 点击Finish后会爆出一个错误(Jar export finished with problems. See deta ...

  3. protobuf 中的嵌套消息的使用 主要对set_allocated_和mutable_的使用

    protobuf的简单的使用,不过还留下了一个问题,那就是之前主要介绍的都是对简单数据的赋值,简单数据直接采用set_xx()即可,但是如果不是简单变量而是自定义的复合类型变量,就没有简单的set函数 ...

  4. java 24小时倒计时案例

    import java.util.Calendar; import java.util.Date; public class Daojishi { static String Countdown=&q ...

  5. centos6.5 网卡服务开机自动启动

    今天打开许久没用的centos之后,发现网络服务器不可用,通过service network restart 依然无法使用,简单记录一下处理过程: 1.通过setup 命令查看Network conf ...

  6. AC日记——小M的作物 bzoj 3438

    3438 思路: 最小割(完全不懂看的题解): s向每个作物连边,s-x ai,x-t bi: 然后s向作物集合连边,cia: 作物集合拆点向t连边,cib: 作物集合第一个点向作物连边INF: 作物 ...

  7. 利用Log4net组件记录日志

    项目中利用Log4net记录日志还是比较方便的,我也按照网上的一些操作进行了实践 参考文章 1:Log4Net使用指南2:LOG4NET日志配置 组件下载 log4net组件下载 1:设置配置文件,这 ...

  8. oracle Update a table with data from another table

    UPDATE table1 t1 SET (name, desc) = (SELECT t2.name, t2.desc FROM table2 t2 WHERE t1.id = t2.id) WHE ...

  9. 「Codeforces Round #441」 Classroom Watch

    Discription Eighth-grader Vova is on duty today in the class. After classes, he went into the office ...

  10. POJ 3420 Quad Tiling (矩阵乘法)

    [题目链接] http://poj.org/problem?id=3420 [题目大意] 给出一个4*n的矩阵,求用1*2的骨牌填满有多少方案数 [题解] 弄出不同情况的继承关系,用矩阵递推即可. [ ...