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

DAY33 贪心算法Ⅱ

122. 买卖股票的最佳时机 II - 力扣(LeetCode)

想到把整体利润分解为每天的利润,就豁然开朗了。

class Solution {
public:
    int maxProfit(vector<int>& prices) {
      int result=0;
      for(int i=1;i<prices.size();i++){
        result+=max(0,prices[i]-prices[i-1]);
      }  
      return result;
    }
};

55. 跳跃游戏 - 力扣(LeetCode)

class Solution {
public:
    bool canJump(vector<int>& nums) {
        int cover=0;
        if(nums.size()==1) return true;
        for(int i=0;i <= cover;i++){
            cover=max(i+nums[i],cover);
            if(cover>=nums.size()-1) return true;
        }
        return false;
    }
};

45. 跳跃游戏 II - 力扣(LeetCode)


http://www.kler.cn/a/585067.html

相关文章:

  • 系统架构的评估的系统的质量属性
  • Java学习--Redis
  • 【机器人-基础知识】欧拉角、旋转矩阵和四元数
  • SQL日期处理
  • 如何在PHP中实现OAuth2认证:安全性与可扩展性
  • 【实战ES】实战 Elasticsearch:快速上手与深度实践-6.2.2GDPR数据脱敏处理
  • Visual stdio2022 opencv cude pytroch与yolov8/可视化工具的环境搭建,不搞VIP,我也要当雷锋
  • TDE透明加密:免改造实现SQLServer数据库安全存储
  • Spring Boot集成Mybatis中如何显示日志
  • AutoGen学习笔记系列(十一)Advanced - Magentic-One
  • LeetCode27移除元素
  • 学习路之TP6 --定制workman命令
  • Java×c艹py
  • SpringBoot 根据配置前缀绑定配置:@ConfigurationProperties
  • Python学习第十三天
  • 第三百七十五节 JavaFX教程 - JavaFX表视图
  • 【氮化镓】开态GaN HEMTs中氧诱导Vth漂移的缺陷演化
  • 【Go学习】04-4-Gorm框架-增删改查事务钩子
  • Redis 源码分析-内部数据结构 ziplist
  • React hook钩子性能优化Hooks的面试常考题目