Problem
Given two non-negative integerslow and high. Return the count of odd numbers between low and high (inclusive).
Examples
Constraints
- 0 <= low <= high <= 10^9
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Tested Python solution for LeetCode 1523 with 22 pytest cases. Generate a practice environment with lcpy.
lcpy gen -n 1523 # by problem number
lcpy gen -s count_odd_numbers_in_an_interval_range # by problem name
low and high. Return the count of odd numbers between low and high (inclusive).
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9].
class Solution:
# Time: O(1)
# Space: O(1)
def count_odds(self, low: int, high: int) -> int:
return (high + 1) // 2 - low // 2
| Time | Space |
|---|---|
| O(1) | O(1) |