leetcode Best Time to Buy and Sell Stock

Posted mxk-star

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode Best Time to Buy and Sell Stock相关的知识,希望对你有一定的参考价值。

//有个图片解释,需要编辑模式才能看。。。。

class Solution { public int maxProfit(int[] prices) { int minprice = Integer.MAX_VALUE; int profit = 0; for(int i=0;i<prices.length;i++){ if(prices[i]<minprice){ minprice = prices[i]; } else if(prices[i]-minprice>profit){ profit = prices[i]-minprice; } } return profit; } }

                                                                                                      技术分享图片



以上是关于leetcode Best Time to Buy and Sell Stock的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 122. Best Time to Buy and Sell Stock II

Leetcode121. Best Time to Buy and Sell Stock

[LeetCode]Best Time to Buy and Sell Stock II

LeetCode OJ 121. Best Time to Buy and Sell Stock

LeetCode Best Time to Buy and Sell Stock

LeetCode - Best Time to Buy and Sell Stock