LeetCode-11~Container with Most Water
来源:互联网 发布:淘宝怎么设置降价提醒 编辑:程序博客网 时间:2024/05/17 21:26
传统的双指针解法仍然存在一些重复计算的问题,因此我改进了此方法多加入了一重判断,效率上提高了不少
public int maxArea2(int[] height) { int dFlag = 0;//1表示前一次左进,2表示右退 int tmp_left = 0;//上次经过计算的水桶的左值 int tmp_right = 0;//上次经过计算的水桶的右值 int max = 0; int left = 0; int tmpHeight = 0; int right = height.length - 1; while (left < right) { if (dFlag == 1) { if (height[left] <= tmp_left) { left++; continue; } } if (dFlag == 2) { if (height[right] <= tmp_right) { right--; continue; } } tmp_left = height[left]; tmp_right = height[right]; max = Math.max(max, Math.min(height[left],height[right])*(right - left)); if (height[left] < height[right]) { left++; dFlag = 1; } else { right--; dFlag = 2; } } return max ; }
阅读全文
0 0
- LeetCode 11: Container With Most Water
- leetcode 11 Container With Most Water
- Leetcode【11】:Container With Most Water
- [leetcode 11] Container With Most Water
- [leetcode 11] Container With Most Water
- LeetCode | #11 Container With Most Water
- leetcode.11---------Container With Most Water
- [LeetCode 11]Container With Most Water
- leetcode 11 Container With Most Water
- leetcode-11 Container With Most Water
- Container With Most Water - LeetCode 11
- [Leetcode 11, Medium] Container With Most Water
- LeetCode 11 - Container With Most Water
- leetcode 11 -- Container With Most Water
- #LeetCode OJ #11 Container With Most Water
- Leetcode #11 Container With Most Water
- leetcode-11Container With Most Water
- leetcode 11 -- Container With Most Water
- 1042字符统计 大小写转换 s[i]-0 是转换 tolower toupper
- 2017-02-22-jquery-选择器带特殊字符出错-需要转义
- 光栅化插值
- Apache工具包方法——Hex.encodeHexString(byte[] data)源码浅析
- 计蒜客_King of the Waves_dfs
- LeetCode-11~Container with Most Water
- 【Python语法笔记】列表的copy()函数
- 指针的的加法该如何设计
- 前端学习资源整理下载
- 记一次不顺畅的沟通
- 局域网内地两台电脑如何传输文件
- 【C++】复制构造函数(拷贝构造函数)和=运算符重载使用的区别
- hustoj的一些改动
- 集合(三)————list集合的子类