Posted on

Description

Submission

class Solution {
public:
    bool canConvertString(string s, string t, int k) {
        if(s.size() != t.size()) return false;
        vector<int> count(26, 0);
        int n = t.size();
        for(int i = 0; i < n; ++i) {
            count[(t[i] - s[i] + 26) % 26]++; 
        }
        int ret = 0;
        for(int i = 1; i < 26; ++i) {
            if(count[i] >= 1) {
                ret = max(ret, (count[i] - 1) * 26 + i);
            }
        }
        return ret <= k;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *