2017.9.12
还是采用字符串来处理
class Solution {
/*
* param k : As description.
* param n : As description.
* return: An integer denote the count of digit k in 1..n
*/
public int digitCounts(int k, int n) {
// write your code here
int count = 0;
for(int i = 0; i <= n; i++){
String tmp = Integer.toString(i);
if(tmp.contains(Integer.toString(k))){
count ++;
}
tmp = tmp.replaceFirst(Integer.toString(k), "");
while(tmp.contains(Integer.toString(k))){
count ++;
tmp = tmp.replaceFirst(Integer.toString(k), "");
}
}
return count;
}
};