Best Time to Buy and Sell Stock
来源:互联网 发布:淘宝众筹 淘宝怎么不管 编辑:程序博客网 时间:2024/05/01 16:03
原题地址:点我传送
贪心算法,遍历数列的每两个数的差取最大即可。
C++:
class Solution {public: int maxProfit(vector<int>& prices) { int diff = 0; for(int i = 0; i < prices.size(); i++) { for(int j = i+1; j < prices.size(); j++) { if(prices[j]-prices[i]>diff) { diff=prices[j]-prices[i]; } } } return diff; }};
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- 【LeetCode】87. Scramble String
- Oracle CASE WHEN 用法介绍
- mysql数据库(1)
- Spring + Maven + Dubbo + MyBatis + Linner + Handlebars-Web开发环境搭建
- 通过Python实现定时器和利用魔法方法改善友好交互
- Best Time to Buy and Sell Stock
- InteliJ Idea 2017.1 for Mac 版 objc[4163]: Class JavaLaunchHelper is implemented in both XXX提示
- Js 函数与对象的区别及原生链的理解
- 算法训练 输出米字形
- Apriori算法
- Merge Two Sorted Lists
- 马尔可夫模型的一步转移概率矩阵Java代码实现
- oracle数据库系列-Archivelog归档文件相关操作
- 建表