3106.cpp (298B)
1 class Solution { 2 public: 3 string getSmallestString(string &s, int k) const { 4 for (int i = 0; i < size(s) && k > 0; ++i) { 5 int dist = min(s[i] - 'a', 'z' - s[i] + 1); 6 s[i] = dist <= k ? 'a' : s[i] - k; 7 k -= dist; 8 } 9 return s; 10 } 11 };