File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 1524. Number of Sub-arrays With Odd Sum
3+ * https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/
4+ * Difficulty: Medium
5+ *
6+ * Given an array of integers arr, return the number of subarrays with an odd sum.
7+ *
8+ * Since the answer can be very large, return it modulo 109 + 7.
9+ */
10+
11+ /**
12+ * @param {number[] } arr
13+ * @return {number }
14+ */
15+ var numOfSubarrays = function ( arr ) {
16+ let even = 0 ;
17+ let odd = 0 ;
18+
19+ for ( let i = 0 , total = 0 ; i < arr . length ; i ++ ) {
20+ total += arr [ i ] ;
21+ odd += + ( total % 2 === 1 ) ;
22+ even += + ( total % 2 === 0 ) ;
23+ }
24+
25+ return ( odd * even + odd ) % ( 1e9 + 7 ) ;
26+ } ;
Original file line number Diff line number Diff line change 5575571507|[ Reformat Date] ( ./1507-reformat-date.js ) |Easy|
5585581512|[ Number of Good Pairs] ( ./1512-number-of-good-pairs.js ) |Easy|
5595591519|[ Number of Nodes in the Sub-Tree With the Same Label] ( ./1519-number-of-nodes-in-the-sub-tree-with-the-same-label.js ) |Medium|
560+ 1524|[ Number of Sub-arrays With Odd Sum] ( ./1524-number-of-sub-arrays-with-odd-sum.js ) |Medium|
5605611528|[ Shuffle String] ( ./1528-shuffle-string.js ) |Easy|
5615621535|[ Find the Winner of an Array Game] ( ./1535-find-the-winner-of-an-array-game.js ) |Medium|
5625631550|[ Three Consecutive Odds] ( ./1550-three-consecutive-odds.js ) |Easy|
You can’t perform that action at this time.
0 commit comments