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

力扣HOT100 - 42. 接雨水

解题思路:

动态规划

感觉不是很好想

class Solution {public int trap(int[] height) {int n = height.length;if (n == 0) return 0;int[] leftMax = new int[n];leftMax[0] = height[0];for (int i = 1; i < n; i++) {leftMax[i] = Math.max(leftMax[i - 1], height[i]);}int[] rightMax = new int[n];rightMax[n - 1] = height[n - 1];for (int i = n - 2; i >= 0; i--) {rightMax[i] = Math.max(rightMax[i + 1], height[i]);}int res = 0;for (int i = 0; i < n; i++) {res += Math.min(leftMax[i], rightMax[i]) - height[i];}return res;}
}

http://www.lryc.cn/news/325737.html

相关文章:

  • 攻防世界-baby_web
  • 数据可视化基础与应用-04-seaborn库从入门到精通01-02
  • 学习 zustand
  • 竞赛 opencv python 深度学习垃圾图像分类系统
  • vsto worksheet中查找关键字【关键字】获取对应的整列 union成一个range
  • flask_restful规范返回值之参数设置
  • 基于java+springboot+vue实现的超市管理系统(文末源码+Lw+ppt)23-354
  • AI大模型学习:开启智能时代的新篇章
  • 【字符串】字符串哈希
  • MacOS快速安装FFmpeg、ffprobe、ffplay
  • 数据结构 之 树习题 力扣oj(附加思路版)
  • 闭包学习,闭包和高阶函数
  • Linux实战笔记(五) shell
  • TCP Wrappers 的使用
  • 数据结构——lesson11排序之快速排序
  • Nacos部署(二)Linux部署Nacos2.3.x集群环境
  • RuoYi 自定义字典列表页面编码翻译
  • GAMES101 学习4
  • Redis中的缓存穿透
  • javaSwing超市收银(txt)
  • Linux 理解文件系统、磁盘结构、软硬链接
  • 智慧商场数字化创新需要有数字能力帮手
  • JS加密解密之应用如何保存到桌面书签
  • 线上linux服务器升级nginx
  • 使用JDK提供的常用工具在多线程编写线程安全和数据同步的程序
  • 八道Python入门级题目及答案详解
  • Git 的cherry-pick含义
  • 大数据中TopK问题
  • 基于SpringBoot+MyBatis+Vue的电商智慧仓储管理系统的设计与实现(源码+LW+部署+讲解)
  • C++经典面试题目(四)