当前位置: 首页 > news >正文

Java | Leetcode Java题解之第123题买卖股票的最佳时机III

题目:

题解:

class Solution {public int maxProfit(int[] prices) {int n = prices.length;int buy1 = -prices[0], sell1 = 0;int buy2 = -prices[0], sell2 = 0;for (int i = 1; i < n; ++i) {buy1 = Math.max(buy1, -prices[i]);sell1 = Math.max(sell1, buy1 + prices[i]);buy2 = Math.max(buy2, sell1 - prices[i]);sell2 = Math.max(sell2, buy2 + prices[i]);}return sell2;}
}
http://www.lryc.cn/news/359240.html

相关文章:

  • Ubuntu22.04之扩展并挂载4T硬盘(二百三十三)
  • Redis实现延迟队列
  • 如何准确查找论文数据库?
  • 翻译《The Old New Thing》- What a drag: Dragging a virtual file (IStream edition)
  • 【FPGA】Verilog语言从零到精通
  • unity打包的WebGL部署到IIS问题
  • GPT-4o:人工智能的新里程碑
  • 发现一个ai工具网站
  • 第二十五章新增H5基础(以及视频~兼容)
  • [英语单词] production quality
  • windows安装nodeJs,以及常用操作
  • MySql part1 安装和介绍
  • SpringBoot打war包并配置外部Tomcat运行
  • 2024.5.31每日一题
  • Oracle 数据库 varchar2 从 4000 扩展到 32k
  • postgressql——事务提交会通过delayChkpt阻塞checkpoint(9)
  • 开发者工具-sources(源代码选项)
  • 没有 rr 头的 kamailio 路由脚本
  • mysql 分区
  • 在龙芯安装docker compose
  • 纯C++做多项式拟合
  • vulnhub靶场之FunBox-9
  • C# 变量与参数详解
  • CentOS7.9部署安装OpenGauss 5.0.2企业版
  • java基础-chapter15(io流)
  • mysql去除重复数据
  • MySQL基础索引知识【索引创建删除 | MyISAM InnoDB引擎原理认识】
  • SJ601-II垂直法阻燃性能测试仪
  • 瑞吉外卖项目学习笔记(二)后台系统的员工管理业务开发
  • Unity OutLine 模型外描边效果