Leetcode 1431. Kids With the Greatest Number of Candies

Problem

There are n kids with candies. You are given an integer array candies, where each candiesi represents the number of candies the ith kid has, and an integer extraCandies, denoting the number of extra candies that you have.

Return a boolean array result of length n, where resulti is true if, after giving the ith kid all the extraCandies, they will have the greatest number of candies among all the kids, or false otherwise.

Note that multiple kids can have the greatest number of candies.

Algorithm

First, calculate the maximum number of candies; then, iterate through each child's candies + extraCandies, determining if it becomes the maximum.

Code

python3 复制代码
class Solution:
    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
        max_val = max(candies)
        ans = []
        for candy in candies:
            if max_val <= candy + extraCandies:
                ans.append(True)
            else:
                ans.append(False)
        return ans
相关推荐
财情双生教练易和中20 分钟前
“找矿大会战”产业链,量化统计研究报告
职场和发展·职业发展·创业创新·程序员创富
不会就选b41 分钟前
算法日常・每日刷题--<贪心>26
数据结构·算法
yuanxi2001 小时前
001267拟扩产光模块:大客户销售如何用价值力读一条扩产公告
人工智能·职场和发展·创业创新·学习方法
Interview Aid1122 小时前
Google SWE Intern Interview Process:OA、Coding 与面试流程详解
面试·职场和发展
hetao17338372 小时前
2026-09-29 hetao1733837 的刷题记录
c++·算法
欣欣之王来了3 小时前
AI合规专项:AI算法透明度的合规要求
人工智能·算法
wzdark3 小时前
分块思想在算法优化中的实践与应用4
算法
Because_of_Her13 小时前
dfs-洪水填充技巧
笔记·算法·深度优先·洪水填充
小静AI工程实验室3 小时前
RSA 算法详解:从模幂原理到 OAEP 加密、PSS 签名与 Python 实验
python·算法
xzal124 小时前
GESP Python笔记
笔记·python·算法