Leetcode Note: Go - Kids With the Greatest Number of Candies
Kids With the Greatest Number of Candies - LeetCode
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/
- Go 言語で取り組んだメモ
回答
[Golang] O(N) - Kids With the Greatest Number of Candies - LeetCode
https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/solutions/890181/golang-o-n/
func kidsWithCandies(candies []int, extraCandies int) []bool {
maxCnt := getMax(candies)
n := len(candies)
res := make([]bool, n)
for i, candy := range candies {
if candy + extraCandies >= maxCnt {
res[i] = true
}
}
return res
}
func getMax(nums []int) int {
res := 0
for _, num := range nums {
if res < num {
res = num
}
}
return res
}