mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
33 lines
990 B
HTML
33 lines
990 B
HTML
|
<p>给定一个整数数组 <code>nums</code> 和一个整数 <code>k</code> ,返回其中元素之和可被 <code>k</code> 整除的(连续、非空) <strong>子数组</strong> 的数目。</p>
|
|||
|
|
|||
|
<p><strong>子数组</strong> 是数组的 <strong>连续</strong> 部分。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>nums = [4,5,0,-2,-3,1], k = 5
|
|||
|
<strong>输出:</strong>7
|
|||
|
<strong>解释:
|
|||
|
</strong>有 7 个子数组满足其元素之和可被 k = 5 整除:
|
|||
|
[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
|
|||
|
</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong> nums = [5], k = 9
|
|||
|
<strong>输出:</strong> 0
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
|
|||
|
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
|
|||
|
<li><code>2 <= k <= 10<sup>4</sup></code></li>
|
|||
|
</ul>
|