1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/和为奇数的子数组数目 [number-of-sub-arrays-with-odd-sum].html
2022-03-29 12:43:11 +08:00

51 lines
1.3 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>给你一个整数数组&nbsp;<code>arr</code>&nbsp;。请你返回和为 <strong>奇数</strong>&nbsp;的子数组数目。</p>
<p>由于答案可能会很大,请你将结果对&nbsp;<code>10^9 + 7</code>&nbsp;取余后返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>arr = [1,3,5]
<strong>输出:</strong>4
<strong>解释:</strong>所有的子数组为 [[1],[1,3],[1,3,5],[3],[3,5],[5]] 。
所有子数组的和为 [1,4,9,3,8,5].
奇数和包括 [1,9,3,5] ,所以答案为 4 。
</pre>
<p><strong>示例 2 </strong></p>
<pre><strong>输入:</strong>arr = [2,4,6]
<strong>输出:</strong>0
<strong>解释:</strong>所有子数组为 [[2],[2,4],[2,4,6],[4],[4,6],[6]] 。
所有子数组和为 [2,6,12,4,10,6] 。
所有子数组和都是偶数,所以答案为 0 。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>arr = [1,2,3,4,5,6,7]
<strong>输出:</strong>16
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>arr = [100,100,99,99]
<strong>输出:</strong>4
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>arr = [7]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 10^5</code></li>
<li><code>1 &lt;= arr[i] &lt;= 100</code></li>
</ul>