源码之家

  • 首页
  • 文章
  • 问答
  • 下载
您的位置: 首页  >  文章  >  leetcode-121-买股票的最佳时机

leetcode-121-买股票的最佳时机

分类: 文章 • 2023-11-03 19:27:21

 题目描述;

leetcode-121-买股票的最佳时机

方法一:O(n) O(1)

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        minprices = float('inf')
        maxprofit = 0
        for i in prices:
            if i<minprices:
                minprices = i
            elif i-minprices>maxprofit:
                maxprofit = i-minprices
        return maxprofit

 

相关推荐

  • 中国股市中的能人:只买这两种形态的股票,会令你大吃一惊!
  • 力扣小白刷题之122题买卖股票的最佳时机Ⅱ
  • LeetCode122-买卖股票的最佳时机2(贪心算法)
  • 第二篇 买卖股票的最佳时机 II
  • 力扣小白刷题之123题买卖股票的最佳时机Ⅲ
  • 22.LeetCode之买卖股票的最佳时机 II(数组中的多次累计的最大差值之和)
  • 力扣(LeetCode) 动态规划之 买卖股票的最佳时机
  • LeetCode刷题-买卖股票的最佳时机
  • 如果每家独角兽的股票各买100块,那么你现在有多少钱?
  • 数据结构与算法作业之“买股票的最佳时机”
  • LeetCode122.买卖股票的最佳时机 II
  • leetcode 122:买卖股票的最佳时机 II
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 源码之家    备案号:   粤ICP备20058927号