Class Solution
java.lang.Object
g0901_1000.s0974_subarray_sums_divisible_by_k.Solution
974 - Subarray Sums Divisible by K.<p>Medium</p>
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of non-empty <strong>subarrays</strong> that have a sum divisible by</em> <code>k</code>.</p>
<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [4,5,0,-2,-3,1], k = 5</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong></p>
<p>There are 7 subarrays with a sum divisible by k = 5:</p>
<p>[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [5], k = 9</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
subarraysDivByK
public int subarraysDivByK(int[] nums, int k)
-