leetcode 121. Best Time to Buy and Sell Stock
来源:互联网 发布:低空飞行淘宝 编辑:程序博客网 时间:2024/05/17 22:56
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.
int maxProfit(int* prices, int pricesSize) {if (prices == NULL)return 0;if (pricesSize < 2)return 0;int max = 0;int k = 0;while (k + 1 < pricesSize){while (k + 1 < pricesSize&&prices[k] > prices[k + 1])k++;int kk = k;while (kk + 1 < pricesSize&&prices[kk + 1] >= prices[k]){if (prices[kk + 1] - prices[k] > max)max = prices[kk + 1] - prices[k];kk++;}k = kk;}return max;}
accepted
0 0
- LeetCode 121. Best Time to Buy and Sell Stock
- [Leetcode] 121. Best Time to Buy and Sell Stock
- [leetcode] 121. Best Time to Buy and Sell Stock
- 【leetcode】121. Best Time to Buy and Sell Stock
- [leetcode] 121. Best Time to Buy and Sell Stock
- 121. Best Time to Buy and Sell Stock LeetCode
- [LeetCode]121. Best Time to Buy and Sell Stock
- Leetcode 121. Best Time to Buy and Sell Stock
- leetcode 121. Best Time to Buy and Sell Stock
- LeetCode 121. Best Time to Buy and Sell Stock
- LeetCode题解:121. Best Time to Buy and Sell Stock
- LeetCode *** 121. Best Time to Buy and Sell Stock
- 【leetcode】121. Best Time to Buy and Sell Stock
- #leetcode#121. Best Time to Buy and Sell Stock
- LeetCode 121. Best Time to Buy and Sell Stock
- 121.[Leetcode]Best Time to Buy and Sell Stock
- leetcode 121. Best Time to Buy and Sell Stock
- Leetcode 121. Best Time to Buy and Sell Stock
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- 笔记本有线网卡未识别无法获取IP地址
- https://和http://区别
- MATLAB批量读取一个文件夹里的图像
- Android开源项目分类汇总(五)ColorPickView、GraphView、UI Style
- leetcode 121. Best Time to Buy and Sell Stock
- 【机器学习】朴素贝叶斯分类
- mysql悲观锁总结和实践
- 对包装类DataInputStream/DataOutputStream的应用
- Ubuntu 14.04 LTS Eclipse没有菜单栏解决方案
- 在DLL中获取自身的路径
- Codeforces 659G Fence Divercity (组合计数)
- Android开源项目分类汇总(六)工具库
- Linux修改内核使得普通用户可以打印kmsg内容