🔥 C++ || Beats 100% || O(n) time, O(1) space || Easy to understand 🔥
Proof beats\n\n\n# Approach\n- If strings are equal then return true.\n- Now we need to check if one string is an anagram of another. I already covered this in 
# Proof beats\n![image.png](https://assets.leetcode.com/users/images/1c200b5b-d5ee-4d9b-a621-37c39eb2d85d_1673461816.9348304.png)\n\n# Approach\n- If **strings are equal** then return **true**.\n- Now we need to check if **one string is an anagram of another**. I already covered this in detail in **my other solution**: [Valid Anagram problem](https://leetcode.com/problems/valid-anagram/solutions/3036897/c-beats-9893-on-time-o1-space-easy-to-understand/).\n- If one string is an anagram of another, then it remains **to check that these strings differ by only two characters**.\n\n# Complexity\n- Time complexity: $ O(n) $\n- Space complexity: $ O(26) = O(1) $\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    bool areAlmostEqual(string s1, string s2) {\n        if (s1 == s2) { return true; }\n        vector<int> letters(26, 0);\n        for (int i = 0; i < s1.size(); i++) {\n            letters[s1[i]-\'a\']++; letters[s2[i]-\'a\']--;\n        }\n        for (int i = 0; i < 26; i++) {\n            if (letters[i] != 0) { return false; }\n        }\n        int k = 0;\n        for (int i = 0; i < s1.size(); i++) {\n            if (s1[i] != s2[i]) { k++; };\n        }\n        return k == 2;\n    }\n};\n```
['C++']