LeetCode Best Time to Buy and Sell Stock
来源:互联网 发布:堺刀司 知乎 编辑:程序博客网 时间:2024/05/17 00:56
就是找后面的数减去前面的数的最大差值,做过。
int maxProfit(vector<int> &prices) {if(prices.size()==0||prices.size()==1)return 0;int maxdiff=0;int minvalue = prices[0];for (int i=1;i<prices.size();i++){if (prices[i]>minvalue){if(prices[i]-minvalue>maxdiff)maxdiff = prices[i]-minvalue;}elseminvalue = prices[i];}return maxdiff;}
0 0
- 【LeetCode】Best Time to Buy and Sell Stock & Best Time to Buy and Sell Stock
- [LeetCode] [LeetCode]Best Time to Buy and Sell Stock
- 【LeetCode with Python】 Best Time to Buy and Sell Stock
- [LeetCode]Best Time to Buy and Sell Stock
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock
- LeetCode Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock III
- Leetcode: Best time to buy and sell a stock I
- Leetcode: Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock III
- [Leetcode] Best Time to Buy and Sell Stock
- [Leetcode] Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock III
- LeetCode : Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock
- leetcode 16: Best Time to Buy and Sell Stock III
- LeetCode Best Time to Buy and Sell Stock
- 用JDBC连接Vertica数据库的例子源代码
- Hibernate Spatial处理空间数据
- iBatis中使用事务
- 二分查找,你真的掌握了吗?
- 《使用Python进行自然语言处理》学习笔记六
- LeetCode Best Time to Buy and Sell Stock
- sap bw dtp 过滤例程 实现了有key值的增量处理
- SensorSimulator安装教程与使用指南
- Linux set unset命令
- UVa 10010 - Where's Waldorf?
- hibernate事务管理
- 从头到尾彻底理解傅里叶变换算法
- Linux 查看shell的几种方法
- 浅谈模板函数的重载解析优先顺序