题解 | #整数中1出现的次数#
整数中1出现的次数(从1到n整数中1出现的次数)
https://www.nowcoder.com/practice/bd7f978302044eee894445e244c7eee6
class Solution { public: int NumberOf1Between1AndN_Solution(int n) { int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = i; j > 0; j /= 10) { if (j % 10 == 1) { cnt++; } } } return cnt; } };
打卡one,通俗易懂版