LeetCode Best Time to Buy and Sell Stock
来源:互联网 发布:淘宝做什么推广好 编辑:程序博客网 时间:2024/04/28 11:21
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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(prices.empty()) return 0; int curr=prices[0],diff=0; for(int i=1;i<prices.size();++i){ if(prices[i]<curr){ curr=prices[i]; }else{ diff=max(diff,prices[i]-curr); } } return diff; }};
- 【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
- sublime text 2添加zen coding
- c/c++ 数字转成字符串, 字符串转成数字
- u-boot编译过程完全分析
- C语言里有"引用传递"吗?到底什么是"引用传递"?
- 便利大师快捷启动工具(ShortcutConsole)更新至V1.3
- LeetCode Best Time to Buy and Sell Stock
- 我被击中了
- 网站设计--数据库集群和数据库垂直分割,水平分割,库表散列
- 调用[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad判断设备
- 例题5.3.2
- poj 1330 Nearest Common Ancestors
- 把本地文件放到服务器端
- malloc() 函数实现
- LeetCode Best Time to Buy and Sell Stock II