文章目录
- 题意
- 思路
- 代码
题意
题目链接
思路
- 按位dp
- 暴力
代码
// 暴力
class Solution {
public:int numberOfBeautifulIntegers(int low, int high, int k) {int l = low / k;int r = high / k;if (low % k)l++;int ans = 0;while (l <= r){int tmp = l * k;if (10 <= tmp && tmp < 99 ||1000 <= tmp && tmp < 9999 ||1000 <= tmp && tmp < 999999 ||100000 <= tmp && tmp < 99999999 ||10000000 <= tmp && tmp < 99999999){int i = 0;int j = 0;while (tmp){int end = tmp % 10;tmp /= 10;end & 1 ? i++ : j++;}if (i == j)ans ++;}else if (tmp >= 99999999)break;l++;}return ans;}
};