本文共 446 字,大约阅读时间需要 1 分钟。
输入一个整数 n ,求1~n这n个整数的十进制表示中1出现的次数
例如,1~13中包含1的数字有1、10、11、12、13因此共出现6次import java.util.*;public class Solution { public int NumberOf1Between1AndN_Solution(int n) { int count = 0; // 循环 1->n for(int i=1;i<=n;i++){ count += f(i); } return count; } // 判断有多少个1 public int f(int n){ String str = n+""; char[] c = str.toCharArray(); int count = 0; for(int i=0;i
转载地址:http://rwssi.baihongyu.com/