rocksc30 / LeetCode

用于力扣刷题打卡
2 stars 0 forks source link

1663. 具有给定数值的最小字符串 #48

Open Ni-Guvara opened 1 year ago

Ni-Guvara commented 1 year ago
class Solution {
public:
    string getSmallestString(int n, int k) {

        string ans;

        for(int i = 1; i <= n;i++)
        {
            int lower = max(1,k-(n-i)*26);
            k -= lower;
            ans.push_back('a' + lower - 1);
        } 
        return ans;
    }
};