javascript -- leetcode 1431. 拥有最多糖果的孩子、1108. IP 地址无效化

题意: 1431. 拥有最多糖果的孩子
在这里插入图片描述
题解: 运用filter()方法将不满足条件的过滤

/**
 * @param {number[]} candies
 * @param {number} extraCandies
 * @return {boolean[]}
 */
var kidsWithCandies = function(candies, extraCandies) {
    
    
    let res = new Array;
    for(let i = 0;i < candies.length;i++){
    
    
        let re = candies.filter(item => item > (candies[i] + extraCandies)); //过滤不符合条件的数组
        if(Object.keys(re).length !== 0){
    
    
            res.push(false);
        }else{
    
     
            res.push(true);
        }
    }
    return res;
};

题意: 1108. IP 地址无效化
在这里插入图片描述
题解:

/**
 * @param {string} address
 * @return {string}
 */
var defangIPaddr = function(address) {
    
    
    return address.replaceAll('.', '[.]');
};

猜你喜欢

转载自blog.csdn.net/sanjun_done/article/details/110291702