【leetcode】121. Best Time to Buy and Sell Stock
来源:互联网 发布:淘宝联盟没有券 编辑:程序博客网 时间:2024/05/16 06:16
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.
/** * @param {number[]} prices * @return {number} */var maxProfit = function(prices) { var ll = prices.length; var value =0; var min = prices[0]; if(ll<2){ return value; } for(var i=1;i<ll;i++){ var price = prices[i]; var diff = price - min; if(diff>value){ value = diff; } if(price<min){ min=price; } } return value;};
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
- 第1章 Odoo安装与配置
- 有哪些冷门却好用的东西可以网购?
- json和xml的区别
- 一道SQL面试题(行列互换)
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- 【leetcode】121. Best Time to Buy and Sell Stock
- Cocos2d-x内存管理 -- 绕不过去的坎
- Unique Paths
- 飛飛(七十一)阅读程序
- zabbix 安装和部署
- Android开发的学习路线
- sws_scale YV12转RGB24图像倒转问题
- OpenGL坐标转换总结
- Stringers golang