I believe this is what's your need, simple, general and fast. Below is an example in Python: Slow Checker The checker is simple, use string to find all number in string from '0' - 'n', and count the match times of k, it's slow but we can use it to check other solutions. import string def knChecker( k, n ): ct = 0 k = str(k) for i in xrange(0,n+1): ct += string.count(str(i),k) return ct Fast and General Solution k ≠ 0 for every k = [1,9],it's much clear that in [0,9] we can find 1 match in first bit; in [0,
Read full article from algorithm - Count the number of Ks between 0 and N - Stack Overflow
No comments:
Post a Comment