Skip to content

Commit 9d02b16

Browse files
committed
✨ [1431] as simple as it sounds // 1 pass
1 parent 1e7dbca commit 9d02b16

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

1431/my_solution.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[]} candies
3+
* @param {number} extraCandies
4+
* @return {boolean[]}
5+
*/
6+
var kidsWithCandies = function (candies, extraCandies) {
7+
let max = Math.max(...candies), result = Array.from({ length: candies.length }).fill(false);
8+
9+
for (let i = 0; i < candies.length; i++) {
10+
if ((candies[i] + extraCandies) >= max) result[i] = true;
11+
}
12+
13+
return result;
14+
};

1431/solution.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[]} candies
3+
* @param {number} extraCandies
4+
* @return {boolean[]}
5+
*/
6+
var kidsWithCandies = function (candies, extraCandies) {
7+
let max = Math.max(...candies), result = Array.from({ length: candies.length }).fill(false);
8+
9+
for (let i = 0; i < candies.length; i++) {
10+
if ((candies[i] + extraCandies) >= max) result[i] = true;
11+
}
12+
13+
return result;
14+
};

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
- [1187. Make Array Strictly Increasing](./1187/)
9595
- [1342. Number of Steps to Reduce a Number to Zero](./1342/)
9696
- [1365. How Many Numbers Are Smaller Than the Current Number](./1365/)
97+
- [1431. Kids With the Greatest Number of Candies](./1431/)
9798
- [1480. Running Sum of 1d Array](./1480/)
9899
- [1512. Number of Good Pairs](./1512/)
99100
- [1569. Number of Ways to Reorder Array to Get Same BST](./1569/)
@@ -153,7 +154,7 @@ Batch create:
153154
NOTE: JS IS HERE
154155
-->
155156
```ssh
156-
chapter=1071 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
157+
chapter=1431 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
157158
```
158159
> then you can use `x` for quick debug.
159160

0 commit comments

Comments
 (0)