leetcode--Best Time to Buy and Sell Stock
来源:互联网 发布:linux rpm怎么安装 编辑:程序博客网 时间:2024/05/22 10:32
Say you have an array for which the ith element is the price of a given stock on dayi.
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) { int max = 0; if(prices.length==0) return max; int min = prices[0]; for(int i=1;i<prices.length;i++){ if(prices[i]>min){ if(prices[i]-min>max){ max = prices[i]-min; } }else{ min = prices[i]; } } 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
- 第八章T2
- 成为一个人
- 6-3(3)
- 第八章T3
- 修改sts设置代码每行长度
- leetcode--Best Time to Buy and Sell Stock
- android平台的三个编译命令----make,mm,mmm
- Android基础知识_Activity组件
- poj 3190 优先队列+贪心
- 动态内存与智能指针
- Cannot convert value '0000-00-00 00:00:00' from column 1 to TIMESTAMP分析及解决办法
- 闰秒对linux的影响分析及解决
- std::advance 给迭代器增加指定偏移量
- docker_restful_api简介