leetcode 233. Number of Digit One

xiaoxiao2021-02-28  46

leetcode 233. Number of Digit One

问题分解: 分治进行计算的思想

public class Solution { public int countDigitOne(int n) { if(n<=0) return 0; int r = 0; for(long m=1;m<=n;m=m*10){ r += (n/m+8)/10*m + (n/m==1?n%m+1:0); } return r; } }

转载请注明原文地址: https://www.6miu.com/read-46408.html

最新回复(0)