解题思路:
(1)计算间距,同时考虑边界
class Solution {
public:
int countOdds(int low, int high) {
int count = (high-low)/2;
if(low%2==0 && high%2==0) return count;
if(low%2!=0 || high%2!=0) return count+1;
return 0;
}
};
解题思路:
(1)计算间距,同时考虑边界
class Solution {
public:
int countOdds(int low, int high) {
int count = (high-low)/2;
if(low%2==0 && high%2==0) return count;
if(low%2!=0 || high%2!=0) return count+1;
return 0;
}
};