Sum of Odd Numbers (Set 14)

Easy

Given an array of integers nums, return the sum of all its odd values, or 0 when every value is even.

Sum of Odd Numbers (Set 14) — the data. This set runs 4 cases: nums holds arrays of 48–48 items, with values from -40 to 55. The hidden cases are the largest of the set.

Example 1

sumOddNumbers()
Input
nums = [33, -8, 25, 4, 2, -9, -2, 8, 28, -1, -40, 13, 13, 43, 46, -11, 33, 36, 18, 5, -10, 33, 47, 5, 22, 13, -4, 6, -30, 15, 34, -1, 8, 7, -1, 4, 35, -16, 36, -33, 24, 25, -14, 17, 24, -27, 32, -36]
Output
279

Why

`sumOddNumbers` returns `279` for this input.

Example 2

sumOddNumbers()
Input
nums = [3, -33, -33, -18, 44, -29, -7, 51, -32, 28, 55, 16, -3, 40, -31, -8, 17, 22, 22, -1, 49, 33, 41, 46, -30, 30, 46, 20, 48, 31, 19, 51, 6, 38, -25, 31, 35, 42, -32, 24, 55, 45, 45, -6, 38, 34, 14, -30]
Output
399

Why

`sumOddNumbers` returns `399` for this input.
Constraints
2 <= nums.length <= 10^4
-10^3 <= nums[i] <= 10^3
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysMath

Implement sumOddNumbers in the editor and return the answer — printing it is never graded.