1523:在区间范围内统计奇数数目
This commit is contained in:
parent
757600a389
commit
7b4586be03
@ -0,0 +1,43 @@
|
||||
//给你两个非负整数 low 和 high 。请你返回 low 和 high 之间(包括二者)奇数的数目。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 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
|
||||
//
|
||||
// Related Topics 数学 👍 48 👎 0
|
||||
|
||||
package leetcode.editor.cn;
|
||||
|
||||
//1523:在区间范围内统计奇数数目
|
||||
public class CountOddNumbersInAnIntervalRange {
|
||||
public static void main(String[] args) {
|
||||
Solution solution = new CountOddNumbersInAnIntervalRange().new Solution();
|
||||
// TO TEST
|
||||
}
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public int countOdds(int low, int high) {
|
||||
return (high + 1) / 2 - (low) / 2;
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<p>给你两个非负整数 <code>low</code> 和 <code>high</code> 。请你返回<em> </em><code>low</code><em> </em>和<em> </em><code>high</code><em> </em>之间(包括二者)奇数的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>low = 3, high = 7
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>3 到 7 之间奇数数字为 [3,5,7] 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>low = 8, high = 10
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>8 到 10 之间奇数数字为 [9] 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= low <= high <= 10^9</code></li>
|
||||
</ul>
|
||||
<div><div>Related Topics</div><div><li>数学</li></div></div><br><div><li>👍 48</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user