[LeetCode OJ]11. Container With Most Water
2016-03-02 23:18
197 查看
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container.
Subscribe to see which companies asked this question
Note: You may not slant the container.
Subscribe to see which companies asked this question
class Solution { public: int maxArea(vector<int>& height) { int left = 0; int right = height.size() - 1; int number = 0; int container = 0; while(left !=right) { container = (right - left) * min(height[right],height[left]); if(container > number) { number = container; } if(height[left] <= height [right]) { left++; } else { right--; } } return number; } };
相关文章推荐
- 使用inpaint例子,去除水印
- 1086. Tree Traversals Again (25)
- 关于vsftp出现Restarting vsftpd (via systemctl): Job for vsftpd.service failed because the control 的解决办法
- MailCore2的使用心得
- ClockRepairs
- PAT 1106. Lowest Price in Supply Chain (25)
- [转]Adb failed to restart! Make sure the plugin is properly configured.
- Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
- copy 与 retain的区别,以及copy与mutablecopy的区别
- INSTALL_FAILED_NO_MATCHING_ABIS 的解决办法
- Troubleshooting: 'Log file sync' Waits
- ADB server didn't ACK,failed to start daemon的解决方法
- 检查Email格式是否合法的正则表达式
- 《Pedestrain detection in Infrared Images》
- 解决 VC2012 ATL 多线程调用 报错:E_UNEXPECTED Catastrophic failure.
- 理解assign,copy,retain
- sqoop连接mysql出现Failed to list databases com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
- 76.You need to display the first names of all customers from the CUSTOMERS table that contain the
- pod的SDK报错,Linker command failed with exit code1(use -v to see invocation)
- pod的SDK报错,Linker command failed with exit code1(use -v to see invocation)