[leetcode] Best Time to Buy and Sell Stock
来源:互联网 发布:手机宽带拨号软件 编辑:程序博客网 时间:2024/06/08 10:57
From : https://leetcode.com/problems/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 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 profit=0; for(int i=0, days=prices.size(), buy=INT_MAX; i<days; i++) { int price = prices[i]; if(price < buy) buy=price; if(profit < price-buy) { profit = price-buy; } } return profit; }};
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
- Android获取手机信息大全
- 实现视图嵌套
- cocos2d-x核心类剖析-coco2d-x触屏实现机制
- 2015062104 - 财务自由
- rs.absolute(),rs.isAfterLast(),rs.next(),rs.relative()简单解释
- [leetcode] Best Time to Buy and Sell Stock
- Matlab 定义类
- AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)
- Android 动画机制解析
- RabbitMQ基础概念详细介绍
- leetcode-94-Binary Tree Inorder Traversal
- 黑马程序员——学习日记之--反射的用法和Eclipse使用
- cocos 框架之-Cocos2d-x 的“HelloWorld” 细节分析
- 异常类已经传参问题