my solution without str casting


  • 0
    M
            if n<10:
                return n
            m=0
            g=0
            while m < n:
                m_prev=m
                m+=9*10**g*(g+1)
                g+=1
            num=10**(g-1)
            diff_index=n-(m_prev+1)
            target_num = num+diff_index/g
            abs_index=n-m_prev-1
            digit_index=abs_index%g
            for _ in range(g-1-digit_index):
                target_num/=10
            return target_num%10
    

    Its pretty slow though and I think can be made better. Im weak at math type problems.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.