[leetcode] 121. Best Time to Buy and Sell Stock
来源:互联网 发布:brew install php扩展 编辑:程序博客网 时间:2024/05/29 15:09
题目:
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.
具体代码:
public class Solution { public int maxProfit(int[] prices) { if(prices.length<=1){ return 0; } int result = 0; int min = prices[0]; for(int i = 1; i < prices.length; i++){ int temp = prices[i] - min; if(result < temp){ result = temp; } if(min > prices[i]){ min = prices[i]; } } return result; }}
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
- require js之define 函数
- python 字典(dict)遍历四种方法的性能
- Openjudge 2.2基本算法之递归和自调用函数 2705:括号匹配问题
- Python的struct
- loading加载动画
- [leetcode] 121. Best Time to Buy and Sell Stock
- 可以拖动的 view
- c++ 在console中控制光标的位置
- JS的replaceAll方法
- Leetcode 338. Counting Bits (Medium) (cpp)
- 360企业安全基础大数据部——Java开发面经
- [iOS 常见报错反馈总结] SIGABRT 和EXC_BAD_ACCESS
- Random使用和生成某区间的随机数
- 关于Qt 中update()和repaint()的区别