美文网首页
leetcode_1431

leetcode_1431

作者: 看到这朵小fa了么 | 来源:发表于2020-06-01 09:21 被阅读0次

    找到最大值,后遍历数组,每一个元素加上额外值大于等于最大值,就可以成为拥有最多糖果的孩子

    var kidsWithCandies = function(candies, extraCandies) {
      let max = Math.max(...candies)
      let result = Array.from(candies).fill(false)
      for(let i=0; i<candies.length; i++) {
          if(candies[i]+extraCandies >=max) {
              result[i] = true
          }
      }
      return result
    };
    

    相关文章

      网友评论

          本文标题:leetcode_1431

          本文链接:https://www.haomeiwen.com/subject/mmhjzhtx.html