1523. Count Odd Numbers in an Interval Range LeetCode Solution
In this guide, you will get 1523. Count Odd Numbers in an Interval Range LeetCode Solution with the best time and space complexity. The solution to Count Odd Numbers in an Interval Range problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Count Odd Numbers in an Interval Range solution in C++
- Count Odd Numbers in an Interval Range solution in Java
- Count Odd Numbers in an Interval Range solution in Python
- Additional Resources
Problem Statement of Count Odd Numbers in an Interval Range
Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).
Example 1:
Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Example 2:
Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9].
Constraints:
0 <= low <= high <= 10^9
Complexity Analysis
- Time Complexity: O(1)
- Space Complexity: O(1)
1523. Count Odd Numbers in an Interval Range LeetCode Solution in C++
class Solution {
public:
int countOdds(int low, int high) {
return (high + 1) / 2 - low / 2;
}
};
/* code provided by PROGIEZ */
1523. Count Odd Numbers in an Interval Range LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1523. Count Odd Numbers in an Interval Range LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.