121. Best Time to Buy and Sell Stock
来源:互联网 发布:mac os 桌面信息白条 编辑:程序博客网 时间:2024/06/16 03:37
121. Best Time to Buy and Sell Stock
思路:
Kadane’s Algorithm
code:
class Solution {public: //[7, 1, 5, 3, 6, 4] //[5, 4, 3, 2] int maxProfit(vector<int>& prices) { if (prices.size() == 0) return 0; int min = prices[0]; int max = 0; for (int i = 1; i < prices.size(); i++) { if (max < prices[i]-min) max = prices[i] - min; if (min > prices[i]) min = prices[i]; } return max; }};
阅读全文
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
- 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程(windows 环境)
- PHP安全编程:从URL的语义进行攻击
- 堆排序中建堆过程的时间复杂度O(n)的证明
- Kotlin学习笔记(十一)集合,区间
- android出现注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 注: 某些输入文件使用了未经检查或不安全的操作。
- 121. Best Time to Buy and Sell Stock
- struts2中的abstract
- Oracle权限
- mysql 简单实现排名功能
- Linux ssh免密登陆相关
- computer vision一些术语-目标识别、目标检测、目标分割、语义分割等
- Linux CAN编程详解
- Logback各Appender详解及配置
- Kotlin-Android世界的一股清流