Flashcards
Find nth digit
Flashcards do conjunto (1)
- 1Input: 11 Output: 0 Explanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.class Solution:
def findNthDigit(self, n: int) -> int:
first, length, size = 1, 1, 9
while n > length * size:
n -= length * size
length += 1
first *= 10
size *= 10
first += (n-1)// length
word = str(first)
return int(word[(n-1)%length])
Informações
- Descrição
- FlashCards sobre Find nth digit, criado por Suhas S em 14-05-2018.
- Criado por
- Suhas S
- Visualizações
- 1
- Avaliação