add: 拥有最多糖果的孩子
This commit is contained in:
parent
46dc5e9b3d
commit
4aa8eba735
@ -362,6 +362,10 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
|
|||||||
- LeetCode 198. 打家劫舍 <https://leetcode-cn.com/problems/house-robber/>
|
- LeetCode 198. 打家劫舍 <https://leetcode-cn.com/problems/house-robber/>
|
||||||
- LintCode 392. 打劫房屋 <https://www.lintcode.com/problem/house-robber/description>
|
- LintCode 392. 打劫房屋 <https://www.lintcode.com/problem/house-robber/description>
|
||||||
|
|
||||||
|
- [拥有最多糖果的孩子](src/array/kids-with-the-greatest-number-of-candies.js)
|
||||||
|
|
||||||
|
- LeetCode 1431. 拥有最多糖果的孩子 <https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies/>
|
||||||
|
|
||||||
## 栈
|
## 栈
|
||||||
|
|
||||||
- [最大矩阵](src/stack/maximal-rectangle.js)
|
- [最大矩阵](src/stack/maximal-rectangle.js)
|
||||||
|
8
src/array/kids-with-the-greatest-number-of-candies.js
Normal file
8
src/array/kids-with-the-greatest-number-of-candies.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* @param {number[]} candies
|
||||||
|
* @param {number} extraCandies
|
||||||
|
* @return {boolean[]}
|
||||||
|
*/
|
||||||
|
export const kidsWithCandies = (candies, extraCandies) => {
|
||||||
|
return candies.map(n => n + extraCandies >= Math.max(...candies))
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
import { kidsWithCandies } from '../../src/array/kids-with-the-greatest-number-of-candies'
|
||||||
|
|
||||||
|
test('拥有最多糖果的孩子', () => {
|
||||||
|
expect(kidsWithCandies([2, 3, 5, 1, 3], 3)).toEqual([true, true, true, false, true])
|
||||||
|
expect(kidsWithCandies([4, 2, 1, 1, 2], 1)).toEqual([true, false, false, false, false])
|
||||||
|
expect(kidsWithCandies([12, 1, 12], 10)).toEqual([true, false, true])
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user