best-time-to-buy-and-sell-stock
来源:互联网 发布:尤克里里谱制作软件 编辑:程序博客网 时间:2024/06/18 01:25
题目:
Say you have an array for which the i th element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.
程序:
class Solution {public: int maxProfit(vector<int> &prices) { int MaxProfit = 0,Min = prices[0]; for(int i=1;i<prices.size();i++) { if(prices[i]>Min) MaxProfit = max(MaxProfit,prices[i]-Min); else Min = prices[i]; } return MaxProfit; }};
阅读全文
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
- (转)移植QT5.6到嵌入式开发板
- Spring IOC原理
- Es 总结
- 浅谈C中的malloc和free释放
- C++ Primer
- best-time-to-buy-and-sell-stock
- JQuery动态显示和隐藏div
- ngrok工具,将本地web服务暴露给互联网
- Machine Learning 2014 by Andrew NG (part 2)
- Sed基本操作
- 基于ubuntu16.04的ceph v10.2.9源码编译
- Kotlin学习资源
- oracle数据会滚
- Cordova下android与javascript的交互