Untitled

 avatar
unknown
plain_text
12 days ago
569 B
3
Indexable
class Solution {
public:
    bool areAlmostEqual(string s1, string s2) {
        int notSame = 0, f = 0;

        vector < int > indexes;

        for(int i=0;i<s1.size();i++) {
            if(notSame == 3) return false;
            if(s1[i]!=s2[i]) {
                notSame++;

                indexes.push_back(i);
            }
        }

        if(notSame == 0)return true;

        if(notSame == 1 || notSame > 2) return false;

        if(s1[indexes[0]] == s2[indexes[1]] && s1[indexes[1]] == s2[indexes[0]])return true;

        return false;
        
    }
};
Editor is loading...
Leave a Comment