|
| 1 | +<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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <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> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p><strong>Note</strong> that <code>0</code> is neither positive nor negative.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> nums = [-2,-1,-1,1,2,3] |
| 14 | +<strong>Output:</strong> 3 |
| 15 | +<strong>Explanation:</strong> There are 3 positive integers and 3 negative integers. The maximum count among them is 3. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong class="example">Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> nums = [-3,-2,-1,0,0,1,2] |
| 22 | +<strong>Output:</strong> 3 |
| 23 | +<strong>Explanation:</strong> There are 2 positive integers and 3 negative integers. The maximum count among them is 3. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong class="example">Example 3:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> nums = [5,20,66,1314] |
| 30 | +<strong>Output:</strong> 4 |
| 31 | +<strong>Explanation:</strong> There are 4 positive integers and 0 negative integers. The maximum count among them is 4. |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= nums.length <= 2000</code></li> |
| 39 | + <li><code>-2000 <= nums[i] <= 2000</code></li> |
| 40 | + <li><code>nums</code> is sorted in a <strong>non-decreasing order</strong>.</li> |
| 41 | +</ul> |
| 42 | + |
| 43 | +<p> </p> |
| 44 | +<p><strong>Follow up:</strong> Can you solve the problem in <code>O(log(n))</code> time complexity?</p> |
0 commit comments