算法珠玑——基本数据类型(1, 2)

https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range/submissions/

class Solution {
public:
    int countOdds(int low, int high) {
        return low%2 + high%2 + (low%2 && high%2 ? (high-low)/2-1 : (high-low)/2); 
    }
};
posted @ 2022-04-02 22:06  千心  阅读(30)  评论(0编辑  收藏  举报