Show problems as
Classic problem #1523EasyMath

Count Odd Numbers in an Interval Range

Real-world version: Odd Numbers Inside a Range
Tracked in this browser only
Read Count Odd Numbers in an Interval Range on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Return how many odd numbers lie in the range from low to high, counting both ends.

Examples

Example 1

Input
low = 1, high = 10
Output
5

The odd numbers from 1 to 10 are 1, 3, 5, 7 and 9.

Example 2

Input
low = 2, high = 2
Output
0

The range holds a single number and it is even.

Example 3

Input
low = 5, high = 5
Output
1

The range holds a single number and it is odd.

Constraints

  • 0 <= low <= high <= 10^9

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def count_odds(low: int, high: int) -> int:
Java
public int countOdds(int low, int high)