2529. Maximum Count of Positive Integer and Negative Integer Easy
1/**
2 * [2529] Maximum Count of Positive Integer and Negative Integer
3 *
4 * Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
5 *
6 * In other words, if the number of positive integers in nums is pos and the number of negative integers is neg, then return the maximum of pos and neg.
7 *
8 * Note that 0 is neither positive nor negative.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: nums = [-2,-1,-1,1,2,3]
13 * Output: 3
14 * Explanation: There are 3 positive integers and 3 negative integers. The maximum count among them is 3.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: nums = [-3,-2,-1,0,0,1,2]
19 * Output: 3
20 * Explanation: There are 2 positive integers and 3 negative integers. The maximum count among them is 3.
21 *
22 * <strong class="example">Example 3:
23 *
24 * Input: nums = [5,20,66,1314]
25 * Output: 4
26 * Explanation: There are 4 positive integers and 0 negative integers. The maximum count among them is 4.
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= nums.length <= 2000
32 * -2000 <= nums[i] <= 2000
33 * nums is sorted in a non-decreasing order.
34 *
35 *
36 * Follow up: Can you solve the problem in O(log(n)) time complexity?
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/
42// discuss: https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn maximum_count(nums: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_2529() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.