---
# System prepended metadata

title: 2529. Maximum Count of Positive Integer and Negative Integer
tags: [Leetcode, Easy, Binary Search]

---

# 2529. Maximum Count of Positive Integer and Negative Integer
###### tags: `Leetcode` `Easy` `Binary Search`
Link: https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/description/
## 思路
## Code
Binary Search
```java=
class Solution {
    public int maximumCount(int[] nums) {
        int pos = nums.length-binarySearch(nums, true);
        int neg = binarySearch(nums, false);
        return Math.max(pos, neg);
    }
    public int binarySearch(int[] nums, boolean equal){
        int left = 0, right = nums.length;
        while(left<right){
            int mid = left+(right-left)/2;
            if(nums[mid]<0 || (equal && nums[mid]==0)) left = mid+1;
            else right = mid;
        }
        return left;
    }
}
```
Brute Force
```python=
class Solution:
    def maximumCount(self, nums: List[int]) -> int:
        neg, pos = 0, 0
        for i,num in enumerate(nums):
            if num>0: 
                pos = len(nums)-i
                break
            elif num<0: neg+=1
        return max(neg, pos)
```