4 ms·
One fun enhancement to this is to avoid the n^2 cost it faces with large integers. def digit_length(n): totlen = 0 n += not n while
by SamReidHughes 7y ago
One fun enhancement to this is to avoid the n^2 cost it faces with large integers.
def digit_length(n):
totlen = 0
n += not n
while n > 0:
klen = 1
k = 10
while n > k * k:
k = k * k
klen *= 2
n = n // k
totlen += klen
return totlen