leetcode - Best Time to Buy and Sell Stock
来源:互联网 发布:mac 强制删除文件夹 编辑:程序博客网 时间:2024/06/04 19:42
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(std::vector<int> &prices) { int min = INT_MAX,max = 0,cur = 0;for (int i = 0; i < prices.size(); i++){if(min > prices[i]) min = prices[i];cur = prices[i] - min;if(max < cur) max = cur;}return max; }};
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
- 探寻C++最快的读取文件的方案
- IT求职
- Linux信号(signal) 机制和Linux信号量(semaphore)机制的区别
- An error was encountered while running(Domain=LaunchSerivcesError, Code=0)
- 面试题 字符串翻转
- leetcode - Best Time to Buy and Sell Stock
- Codecademy_HTML小结
- Java面向对象程序设计 java实验报告第三个
- hdu 3397 Sequence operation(线段树)
- 完整删除Grid Control Agent
- 误差的浮点操作
- 潜在误差精度误差
- Dropping water balloons - UVa 10934 dp
- 【BZOJ】【P2422】【Times】【题解】【离散化+前缀和】