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

【力扣 简单 C】121. 买卖股票的最佳时机

目录

题目

解法一:动态规划


题目

解法一:动态规划

int max(int a, int b) {return a > b ? a : b;
}int min(int a, int b) {return a < b ? a : b;
}int maxProfit(int* prices, int pricesSize) {int dp[1][2] = {prices[0], 0};for (int i = 1; i < pricesSize; i++) {dp[0][1] = max(dp[0][1], prices[i] - dp[0][0]);dp[0][0] = min(dp[0][0], prices[i]);}return dp[0][1];
}

相关文章:

  • GitHub Actions 实现 AWS ECS 服务的多集群安全重启方案
  • 【AI实践】Mac一天熟悉AI模型智能体应用(百炼版)
  • STM32中Usart的使用
  • 一个简单测试Deepseek吞吐量的脚本,国内环境可跑
  • 1.1 基于Icarus Verilog、ModelSim和Vivado对蜂鸟E203处理器进行仿真
  • HarmonyOS File和base64字符串转换
  • Note2.2 机器学习训练技巧:Batch and Momentum(Machine Learning by Hung-yi Lee)
  • C语言二级指针与多级指针
  • cannot import name ‘TextKwargs‘ from ‘transformers.processing_utils‘
  • 【LeetCode 热题 100】438. 找到字符串中所有字母异位词——(解法二)定长滑动窗口+数组
  • LeetCode Hot 100 找到字符串中所有字母异位词
  • 编译流程详解
  • 利用ROS打印novatel_msgs/INSPVAX
  • 滑坡监测接收机市场分析
  • libxlsxwriter: 一个轻量级的跨平台的C++操作Excel的开源库
  • 个人日记本小程序开发方案(使用IntelliJ IDEA)
  • python解释器 与 pip脚本常遇到的问题汇总
  • 【stm32】HAL库开发——CubeMX配置ADC
  • Minio入门+适配器模式(实战教程)
  • ZooKeeper深度面试指南三