0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

day3 at leetcode

0
Posted at
  1. Kids With the Greatest Number of Candies
class Solution:
    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
        max_kid = max(candies)#最大値を求める
        result = []#出力を定義
        for i in range(len(candies)):
            compare = candies[i] + extraCandies
            if compare >= max_kid:#判定と結果追加
                result.append(True)
            else:
                result.append(False)
        return result

簡単

もっと小さくできるらしい

class Solution:
    def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]:
        max_kid = max(candies)
        return [candy + extraCandies >= max_kid for candy in candies]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?