1663. Smallest String With A Given Numeric Value

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1663

class Solution:
    def getSmallestString(self, n: int, k: int) -> str:
        res = ['a'] * n
        i, d = n - 1, k - n
        while d > 25:
            res[i] = 'z'
            d -= 25
            i -= 1
        res[i] = chr(ord(res[i]) + d)
        return ''.join(res)