The following code snippet is written for returning the numbers which don't contain the number which having repeated digits.
For example, if an input is 7 the program should return the count of numbers 7 counts of (1,2,3,4,5,6,7)
then output should be 7
.
If an input is 23 the program should return the count of numbers 23
count of (1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,23)
here the count excluded the numbers like 11,22 and output should be 21
.
To optimize this code what should I do?
def nonrep1(n):
return sum(all(c != d for c, d in zip(str(i), str(i)[1:])) for i in xrange(1, n+1))
I have to optimize this code, how do I do that?
test case 1:
simple input:
7
simple output:
7
test case 2:
simple input:
3456
simple output:
2562