233. 数字 1 的个数:给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数。
题目:给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数。1、暴力求解法:class Solution {public: int countDigitOne(int n) { int res=0; for(int i=1;i<=n;i++){ string str=to_string(i); res+=count(str.begin(),str.end(),'1');