*LeetCode-Container With Most Water
2015-09-19 10:53
495 查看
读题就读了很久
解法很巧妙 两个指针在两端 向中心挪动 因为只要其中一个高 它下次就不用挪 挪另一个 因为挪了没有意义 过程中keep max area
解法很巧妙 两个指针在两端 向中心挪动 因为只要其中一个高 它下次就不用挪 挪另一个 因为挪了没有意义 过程中keep max area
public class Solution { public int maxArea(int[] height) { int i = 0; int j = height.length - 1; int area = 0; while ( i < j ){ area = Math.max( area, Math.min(height[i], height[j]) * (j-i) ); if ( height[i] > height[j] ) j --; else i ++; } return area; } }
相关文章推荐
- office outlook 2010/2013 问题 求助 help
- A. Raising Bacteria
- 错误Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1
- 纪念人工智能(AI)奠基60周年(续)
- Raising Bacteria (Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] )
- LightOJ 1282 Leading and Trailing(截取前n位输出)
- codeforces #320 div 2A - Raising Bacteria (位运算)
- zoj1163The Staircases
- 【CodeForces】80D Time to Raid Cowavans 分块
- 关于retain循环引用对象解决图解
- golang学习笔记之---waitgoup
- LEETCODE-Climbing Stairs
- 解决Command /usr/bin/codesign failed with exit code 1.rtfd
- LeetCode -- Contains Duplicate II
- Thumbnails
- wait()和sleep()的区别
- RAID技术介绍
- UVa 10780 - Again Prime? No Time.
- failed to install sourceTree in win7