C++ || 2 Pointers || Easiest Solution
Approach\n Describe your approach to solving the problem. \nSince we have to perform swap only once. \nTraverse through the string and store the first unequal c
# Approach\n<!-- Describe your approach to solving the problem. -->\nSince we have to perform swap only once. \nTraverse through the string and store the first unequal character in strings 1 and 2 and last unequal character in strings 1 and 2. After swapping both if we both are same, return true else false;\nE.g. "bank" and "kanb" . Here b (str1[0])and k (str2[0]) of string 1 and string 2 are not same. Similarly, k (str1[3]) and b (str2[3]) are not same. So, if we swap these indeces in any of the strings are compare them. We will get our answer.\n# Complexity\n- Time complexity : $$O(n)$$ \n\n- Space complexity : $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    bool areAlmostEqual(string s1, string s2) {\n        if(s1 == s2)\n        return true;\n        int left = 0, right = s1.size()-1;\n        while(s1[left]==s2[left])\n        left++;\n        while(s1[right]==s2[right])\n        right--;\n        swap(s2[right],s2[left]);\n        return s1==s2;\n    }\n};\n```\n![EZqg6p1WsAIQiua.jpg](https://assets.leetcode.com/users/images/c945e5de-ec21-4b50-ae28-c92ea694dcb9_1672818572.1840203.jpeg)\n\n
['Two Pointers', 'String', 'C++']