Leetcode11(Java)
来源:互联网 发布:java socket 中断 编辑:程序博客网 时间:2024/06/03 18:37
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 and n is at least 2.
public int maxArea(int[] height) { if(height.length==2)return Math.min(height[0], height[1]); int maxarea = 0; int left=0,right=height.length-1; while(left<height.length-1 && right>=0 && right>left){ maxarea = Math.max(maxarea, Math.min(height[left], height[right]) * (right - left)); if (height[left] > height[right]) { right--; } else { left++; } } return maxarea; }
阅读全文
0 0
- Leetcode11(Java)
- leetcode11
- leetcode11.ContainerWithMostWater
- Leetcode11: Remove Element
- Leetcode11 Pow(x,n)
- LeetCode11. Container With Most Water(思维题:选择左右边使得容器所盛水最多)
- Leetcode11: Container with most water
- leetcode11.Linked List Cycle II
- [LeetCode11]Container With Most Water
- Binary Tree Inorder Traversal leetCode11
- LeetCode11:Container With Most Water
- leetcode11 Container With Most Water
- leetcode11 Container With Most Water
- LeetCode11:Container With Most Water
- Leetcode11 Container With Most Water
- leetcode11:Container With Most Water
- LeetCode11: Container With Most Water
- leetcode11. Container With Most Water
- 注解(笔记)
- nginx: [emerg] bind() to 0.0.0.0:9090 failed (13: Permission denied)
- 常用集合Map,List,Set
- Springmvc分页
- 【偶现】【reboot】【一】java.lang.RuntimeException
- Leetcode11(Java)
- poj1294拓扑排序
- Mysql数据库基本命令和基本类型总结
- jQuery(4)__jQuery基础<Ajax>
- Git简介及入门
- laravel笔记-Eloquent ORM(关联关系)
- 插件化框架 RePlugin 应用之一:配置及内置插件
- Spring Boot 数据缓存 Cache
- css 媒体查询