LyWang

digit_count

Nov 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     /**
  4.      * @param k: An integer
  5.      * @param n: An integer
  6.      * @return: An integer denote the count of digit k in 1..n
  7.      */
  8.     int digitCounts(int k, int n) {
  9.         // write your code here
  10.         int result=1;
  11.         if (k==0){k=10;}
  12.         while(n!=1){
  13.             n = n/k;
  14.             result += n;
  15.         }
  16.         return result;
  17.     }
  18. };
Add Comment
Please, Sign In to add comment