mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given an array <code>nums</code> sorted in <strong>non-decreasing</strong> order, return <em>the maximum between the number of positive integers and the number of negative integers.</em></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>In other words, if the number of positive integers in <code>nums</code> is <code>pos</code> and the number of negative integers is <code>neg</code>, then return the maximum of <code>pos</code> and <code>neg</code>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p><strong>Note</strong> that <code>0</code> is neither positive nor negative.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [-2,-1,-1,1,2,3]
 | 
						|
<strong>Output:</strong> 3
 | 
						|
<strong>Explanation:</strong> There are 3 positive integers and 3 negative integers. The maximum count among them is 3.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [-3,-2,-1,0,0,1,2]
 | 
						|
<strong>Output:</strong> 3
 | 
						|
<strong>Explanation:</strong> There are 2 positive integers and 3 negative integers. The maximum count among them is 3.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums = [5,20,66,1314]
 | 
						|
<strong>Output:</strong> 4
 | 
						|
<strong>Explanation:</strong> There are 4 positive integers and 0 negative integers. The maximum count among them is 4.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= nums.length <= 2000</code></li>
 | 
						|
	<li><code>-2000 <= nums[i] <= 2000</code></li>
 | 
						|
	<li><code>nums</code> is sorted in a <strong>non-decreasing order</strong>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Follow up:</strong> Can you solve the problem in <code>O(log(n))</code> time complexity?</p>
 |