没人想到,把数字拼接成字符串 判断字符1的个数么?
好吧,面试可能会被虐
public class Solution { public int NumberOf1Between1AndN_Solution(int n) { String s = ""; int number = 0; for(int i = 1; i<=n; i++){ s = s + i; } char[] cs = s.toCharArray(); for(int i = 0; i<cs.length; i++){ if(cs[i]=='1'){ number ++; } } return number; } }