mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
feat: add Number of Sub-arrays With Odd Sum (#1139)
* add Number of Sub-arrays With Odd Sum * Update 1524.c add new line at the end * Rename README.md to DIRECTORY.md * chore: apply suggestions from code review Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
parent
dee9ac73cd
commit
ea775e7a04
@ -95,5 +95,6 @@
|
|||||||
| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/) | [C](./src/1184.c) | Easy |
|
| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/) | [C](./src/1184.c) | Easy |
|
||||||
| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [C](./src/1189.c) | Easy |
|
| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [C](./src/1189.c) | Easy |
|
||||||
| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C](./src/1207.c) | Easy |
|
| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C](./src/1207.c) | Easy |
|
||||||
|
| 1524 | [Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/) | [C](./src/1524.c) | Medium |
|
||||||
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/) | [C](./src/1752.c) | Easy |
|
| 1752 | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/) | [C](./src/1752.c) | Easy |
|
||||||
| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium |
|
| 2130 | [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/) | [C](./src/2130.c) | Medium |
|
||||||
|
24
leetcode/src/1524.c
Normal file
24
leetcode/src/1524.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Counting whole summ. evens sums number and odd summs number.
|
||||||
|
// Runtime: O(n),
|
||||||
|
// Space: O(1)
|
||||||
|
int numOfSubarrays(int* arr, int arrSize){
|
||||||
|
int result = 0;
|
||||||
|
int curSumm = 0;
|
||||||
|
int currOddSumms = 0;
|
||||||
|
int currEvenSumm = 0;
|
||||||
|
int modulo = 1000000000 + 7;
|
||||||
|
|
||||||
|
for(int i = 0; i < arrSize; i++){
|
||||||
|
curSumm += arr[i];
|
||||||
|
if (curSumm % 2 == 0){
|
||||||
|
currEvenSumm++;
|
||||||
|
result = (result + currOddSumms) % modulo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currOddSumms++;
|
||||||
|
result = (result + 1 + currEvenSumm) % modulo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result % modulo;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user