LeetCodemaxarea javascript leetcode:leetcode题解

weixin_42557 2 0 zip 2024-09-21 00:09:04

LeetCode maxarea javascript-leetcode leetcode题解。盛最多水的容器,采用双指针法,面积计算为宽乘高,宽为两侧索引距离,高为最短木板决定。


var maxArea = function(height) {  

    let max = 0;  

    let left = 0; // 左侧木板指针  

    let right = height.length -1; // 右侧木板指针  

    while(left < right){  

        let current = (right - left) * Math.min(height[left],height[right]) // 当前木板的距离 * 最小高度即为面积  

        max = Math.max(current,max) // 更新目前的最大面积  

        height[left] < height[right] ? left++ : right--;  

    }  

    return max;  

};  

数组中重复的数字


var findRepeatNumber = function(nums) {  

    let map = new Map();  

    let result = 0;  

用户评论
请输入评论内容
评分:
暂无评论