We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接:https://leetcode-cn.com/problems/container-with-most-water/
解题思路:
/** * @param {number[]} height * @return {number} */ var maxArea = function (height) { let result = 0; // 利用双循环遍历数组(即每一根柱子),保证遍历到每一个值 for (let i = 0; i < height.length - 1; i++) { for (let j = 0; j < height.length; j++) { // 容积能装的水量,等于两个柱子中最低的柱子高度,乘以两个柱子之间的距离 // 计算两个柱子的最小高度 const minHeight = Math.min(height[i], height[j]); // 用最小高度乘以柱子的距离,即为当前两根柱子所围面积 const area = minHeight * (j - i); // 对比当前值和缓存的面积,取最大值保存,当完成循环时,result中保存的就是最大值。 result = Math.max(area, result); } } return result; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接:https://leetcode-cn.com/problems/container-with-most-water/
解题思路:
The text was updated successfully, but these errors were encountered: