Java实现-接雨水
来源:互联网 发布:广电总局下架网络剧 编辑:程序博客网 时间:2024/06/11 19:49
public class Solution { /** * @param heights: an array of integers * @return: a integer */ public int trapRainWater(int[] heights) { // write your code here int left = 0, right = heights.length - 1; int res = 0; if(left >= right) return res; int leftheight = heights[left]; int rightheight = heights[right]; while(left < right) { if(leftheight < rightheight) { left ++; if(leftheight > heights[left]) { res += (leftheight - heights[left]); } else { leftheight = heights[left]; } } else { right --; if(rightheight > heights[right]) { res += (rightheight - heights[right]); } else { rightheight = heights[right]; } } } return res; }}
阅读全文
0 0
- Java实现-接雨水
- 接雨水
- 接雨水
- 接雨水
- LintCode-接雨水
- LintCode:接雨水
- LintCode:接雨水
- 接雨水 lintcode
- 接雨水问题(C++)
- 接雨水问题
- lintcode[363]:接雨水
- LintCode:M-接雨水
- 接雨水-LintCode
- 接雨水 II-LintCode
- LintCode rain trap 接雨水
- [LintCode 363] 接雨水(Python)
- **[Lintcode]Trapping Rain Water 接雨水
- 接雨水最大面积Trapping Rain Water
- 使用gdb调试多进程和多线程程序
- 2017年上海金马五校程序设计竞赛:Problem A : STEED Cards
- tar命令
- Java基础回顾之集合
- JS常用正则表达式和JS控制输入框输入限制(数字、汉字、字符)
- Java实现-接雨水
- CSS3响应式布局之弹性盒子
- nfs的一些配置
- Python中的运算符
- ubuntu使用watch命令实时监测显卡
- js事件委托
- 15.activiti工作流-工作流定义的角色组(了解)
- 【ESP8266】在ESP8266上使用JavaScript语言开发
- sg函数的一些题