《剑指Offer》刷题笔记——面试题63. 股票的最大利润

难度:中等

一、题目描述:

在这里插入图片描述

二、解题分析:

1、剑指解析

在这里插入图片描述

2、代码实现

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        inf = int(1e9)
        minprice = inf
        maxprofit = 0
        for price in prices:
            maxprofit = max(price - minprice, maxprofit)
            minprice = min(price, minprice)
        return maxprofit
发布了132 篇原创文章 · 获赞 154 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_34108714/article/details/104780801
今日推荐