Press "Enter" to skip to content

花花酱 LeetCode 121. Best Time to Buy and Sell Stock

题目大意: 给你一只股票每天的价格,如果只能做一次交易(一次买进一次卖出)问你最多能赚多少钱。

Problem:

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.

Example 1:

Example 2:

 

Idea:

DP

Solution 1:

C++

C++ / reduce to maximum subarray

Related Problems:

请尊重作者的劳动成果,转载请注明出处!花花保留对文章/视频的所有权利。
如果您喜欢这篇文章/视频,欢迎您捐赠花花。
If you like my articles / videos, donations are welcome.

Buy anything from Amazon to support our website
您可以通过在亚马逊上购物(任意商品)来支持我们

Paypal
Venmo
huahualeetcode
微信打赏

Be First to Comment

Leave a Reply