Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 540 Bytes

File metadata and controls

23 lines (15 loc) · 540 Bytes

LeetCode Problems

1523. Count Odd Numbers in an Interval Range

class Solution {
    fun countOdds(low: Int, high: Int): Int {
        // basically, odd numbers in range is (n2 - n1) / 2.
        // but if n1 or n2 is odd, have to count inclusive.
        return (high - low) / 2  + if (high % 2 == 1 || low % 2 == 1) 1 else 0
    }
}