1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/乘积为正数的最长子数组长度 [maximum-length-of-subarray-with-positive-product].html
2022-03-29 12:43:11 +08:00

43 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code>&nbsp;,请你求出乘积为正数的最长子数组的长度。</p>
<p>一个数组的子数组是由原数组中零个或者更多个连续数字组成的数组。</p>
<p>请你返回乘积为正数的最长子数组长度。</p>
<p>&nbsp;</p>
<p><strong>示例&nbsp; 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,-2,-3,4]
<strong>输出:</strong>4
<strong>解释:</strong>数组本身乘积就是正数,值为 24 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [0,1,-2,-3,-4]
<strong>输出:</strong>3
<strong>解释:</strong>最长乘积为正数的子数组为 [1,-2,-3] ,乘积为 6 。
注意,我们不能把 0 也包括到子数组中,因为这样乘积为 0 ,不是正数。</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [-1,-2,-3,0,1]
<strong>输出:</strong>2
<strong>解释:</strong>乘积为正数的最长子数组是 [-1,-2] 或者 [-2,-3] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
<li><code>-10^9 &lt;= nums[i]&nbsp;&lt;= 10^9</code></li>
</ul>
<p>&nbsp;</p>