Skip to content

Commit eeaf182

Browse files
committed
Add solution #2529
1 parent 0cadf6a commit eeaf182

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
2469|[Convert the Temperature](./2469-convert-the-temperature.js)|Easy|
332332
2482|[Difference Between Ones and Zeros in Row and Column](./2482-difference-between-ones-and-zeros-in-row-and-column.js)|Medium|
333333
2490|[Circular Sentence](./2490-circular-sentence.js)|Easy|
334+
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
334335

335336
## License
336337

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 2529. Maximum Count of Positive Integer and Negative Integer
3+
* https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/
4+
* Difficulty: Easy
5+
*
6+
* Given an array nums sorted in non-decreasing order, return the maximum
7+
* between the number of positive integers and the number of negative integers.
8+
*
9+
* In other words, if the number of positive integers in nums is pos and the
10+
* number of negative integers is neg, then return the maximum of pos and neg.
11+
*
12+
* Note that 0 is neither positive nor negative.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {number}
18+
*/
19+
var maximumCount = function(nums) {
20+
const result = nums.reduce(([neg = 0, pos = 0], n) => {
21+
return [neg + (n < 0 ? 1 : 0), pos + (n > 0 ? 1 : 0)];
22+
}, []);
23+
return Math.max(...result);
24+
};

0 commit comments

Comments
 (0)