Skip to content

Commit 9295659

Browse files
committed
Upsert 1523-count-odd-numbers-in-an-interval-range.rs
1 parent cdd4d34 commit 9295659

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn count_odds(low: i32, high: i32) -> i32 {
3+
let mut ret = 0;
4+
5+
if low % 2 == 1 { ret += 1 }
6+
if high % 2 == 1 { ret += 1 }
7+
8+
if ret == 2 {
9+
ret += (high - low)/2 - 1
10+
} else {
11+
ret += (high - low)/2
12+
}
13+
ret
14+
}
15+
}

0 commit comments

Comments
 (0)