Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 727 Bytes

File metadata and controls

31 lines (26 loc) · 727 Bytes

1523. 在区间范围内统计奇数数目

给你两个非负整数 lowhigh 。请你返回 lowhigh 之间(包括二者)奇数的数目。

示例 1:

输入: low = 3, high = 7
输出: 3
解释: 3 到 7 之间奇数数字为 [3,5,7] 。

示例 2:

输入: low = 8, high = 10
输出: 1
解释: 8 到 10 之间奇数数字为 [9] 。

提示:

  • 0 <= low <= high <= 10^9

题解 (Ruby)

1. 数学

# @param {Integer} low
# @param {Integer} high
# @return {Integer}
def count_odds(low, high)
    return (high - low + low % 2 + high % 2) / 2
end