Skip to content

Commit f9a56e2

Browse files
authored
Create count-odd-numbers-in-an-interval-range.cpp
1 parent a781f97 commit f9a56e2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int countOdds(int low, int high) {
7+
return (high + 1) / 2 - ((low - 1) + 1) / 2;
8+
}
9+
};

0 commit comments

Comments
 (0)