File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 557
557
1507|[ Reformat Date] ( ./1507-reformat-date.js ) |Easy|
558
558
1512|[ Number of Good Pairs] ( ./1512-number-of-good-pairs.js ) |Easy|
559
559
1519|[ 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|
560
561
1528|[ Shuffle String] ( ./1528-shuffle-string.js ) |Easy|
561
562
1535|[ Find the Winner of an Array Game] ( ./1535-find-the-winner-of-an-array-game.js ) |Medium|
562
563
1550|[ Three Consecutive Odds] ( ./1550-three-consecutive-odds.js ) |Easy|
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
+ } ;
You can’t perform that action at this time.
0 commit comments