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 candies[i] 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 result[i] 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
相关推荐
橘颂TA8 分钟前
机器人+工业领域=?
算法·机器人
小O的算法实验室1 小时前
2025年TRE SCI1区TOP,随机环境下无人机应急医疗接送与配送的先进混合方法,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
程序员杰哥1 小时前
软件测试之压力测试详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·压力测试
小白程序员成长日记1 小时前
2025.11.06 力扣每日一题
算法·leetcode
暴风鱼划水2 小时前
算法题(Python)数组篇 | 4.长度最小的子数组
python·算法·力扣
gugugu.2 小时前
算法:二分算法类型题目总结---(含二分模版)
算法
大G的笔记本2 小时前
算法篇常见面试题清单
java·算法·排序算法
7澄12 小时前
深入解析 LeetCode 数组经典问题:删除每行中的最大值与找出峰值
java·开发语言·算法·leetcode·intellij idea
AI科技星2 小时前
宇宙的几何诗篇:当空间本身成为运动的主角
数据结构·人工智能·经验分享·算法·计算机视觉
前端小L2 小时前
二分查找专题(二):lower_bound 的首秀——精解「搜索插入位置」
数据结构·算法