题解 | #从1到n整数中1出现的次数# 毫无感情,硬解
整数中1出现的次数(从1到n整数中1出现的次数)
https://www.nowcoder.com/practice/bd7f978302044eee894445e244c7eee6
public class Solution { public int NumberOf1Between1AndN_Solution(int n) { StringBuilder sp = new StringBuilder(); for (int i = 1; i <= n; i++) { sp.append(i); } String str = sp.toString(); int mi = str.replaceAll("1", "").length(); int max = str.length() - mi; return max; } }#剑指offr#