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
相关推荐
玖玥拾5 分钟前
LeetCode 1 两数之和
算法·leetcode·职场和发展
Cccp.1235 分钟前
【leetcode】(一)认识复杂度和简单排序算法
算法·排序算法
boheweidexiatian14 分钟前
如何系统性地准备面试,把通过率提到最高?
面试·职场和发展·求职招聘
旖旎夜光14 分钟前
LeetCode 974:和可被 K 整除的子数组(前缀和) —— 题解
数据结构·c++·算法·leetcode·前缀和
无限码力18 分钟前
拼多多笔试真题 2026-8-30【唯一入栈出库序列】
算法·pdd笔试真题·拼多多春招笔试真题·拼多多秋招笔试真题·拼多多笔试真题题解·拼多多最新笔试题库
lvwangshu18 分钟前
分治:序列分治(CDQ)与点分治
算法·分治
无限码力23 分钟前
2026-8-30拼多多笔试真题-哪个查阅窗能留空(C++/Py/Java /Js/Go)
算法·pdd·pdd笔试真题·拼多多春招笔试真题·拼多多秋招笔试真题·拼多多笔试真题题解·拼多多笔试题解
luj_176843 分钟前
毒素驱动的生物自毁机制探析
服务器·c语言·开发语言·经验分享·算法
一水鉴天1 小时前
问题分类的三元组映射体系与求解方法论 20260901(千问)
人工智能·算法·机器学习
breeze jiang1 小时前
LangChain Memory 实战:用 InMemoryChatMessageHistory 管理多轮对话
前端·算法·langchain