C语言 | Leetcode C语言题解之第121题买卖股票的最佳时机

题目:

题解:

int maxProfit(int* prices, int pricesSize) {
    if(pricesSize==0)return 0;
    int dp[pricesSize][2];
    memset(dp,0,sizeof(dp));
    dp[0][0]=-prices[0];
    dp[0][1]=0;
    for(int i=1;i<pricesSize;i++){
        dp[i][0]=fmax(dp[i-1][0],-prices[i]);
        dp[i][1]=fmax(dp[i-1][1],dp[i-1][0]+prices[i]);
    }
    return dp[pricesSize-1][1];
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 00:54:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 00:54:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 00:54:04       82 阅读
  4. Python语言-面向对象

    2024-06-06 00:54:04       91 阅读

热门阅读

  1. django接入djangorestframework-simplejwt步骤

    2024-06-06 00:54:04       31 阅读
  2. blender从视频中动作捕捉,绑定到人物模型

    2024-06-06 00:54:04       24 阅读
  3. 随心笔记,第四更

    2024-06-06 00:54:04       19 阅读
  4. AIGC工具汇总介绍

    2024-06-06 00:54:04       30 阅读
  5. Blender 学习笔记(一)快捷键记录

    2024-06-06 00:54:04       25 阅读
  6. EasyExcel前端怎么使用:深度解析与实用指南

    2024-06-06 00:54:04       25 阅读
  7. CSS:transform作用

    2024-06-06 00:54:04       31 阅读
  8. EasyExcel

    2024-06-06 00:54:04       21 阅读
  9. K-means 聚类算法和K-means ++聚类算法详解【5】

    2024-06-06 00:54:04       29 阅读
  10. 顺序表应用7:最大子段和之分治递归法

    2024-06-06 00:54:04       30 阅读
  11. 设计模式-模板方法模式

    2024-06-06 00:54:04       33 阅读
  12. 02-2.3.6 顺序表和链表的比较

    2024-06-06 00:54:04       26 阅读
  13. Unity3D 基于YooAssets的资源管理详解

    2024-06-06 00:54:04       31 阅读