JAVA || C++ || EXPLAINED || FASTER THAN 100% || VECTOR
C++\nRuntime: 0 ms\nMemory Usage: 6.2 MB\n\nclass Solution {\npublic:\n    bool areAlmostEqual(string s1, string s2) {\n        vector<int> cnt;\n        // fin
# C++\n**Runtime: 0 ms\nMemory Usage: 6.2 MB**\n```\nclass Solution {\npublic:\n    bool areAlmostEqual(string s1, string s2) {\n        vector<int> cnt;\n        // find the number of diff chars \n        for(int i=0;i<s1.size()&& cnt.size()<3;i++){\n            if(s1[i]!=s2[i]){\n                cnt.push_back(i);\n            }\n        }\n        // when the chars are exactly the same or there is only one pair of diff chars, check if swapping makes them equal then return true\n        return (cnt.size()==0) || ((cnt.size()==2) && (s1[cnt[0]]==s2[cnt[1]] || s1[cnt[1]]==s2[cnt[0]]));\n    }\n};\n```\n# JAVA\n**Runtime: 0 ms, faster than 100.00% of Java online submissions\nMemory Usage: 37.2 MB, less than 100.00% of Java online submissions**\n```\nimport java.util.*;  \nclass Solution {\n    public boolean areAlmostEqual(String s1, String s2) {\n        Vector<Integer> cnt = new Vector<>();  \n        // find the number of diff chars \n        for(int i=0;i<s1.length() && cnt.size()<3;i++){\n            if(s1.charAt(i)!=s2.charAt(i)){\n                cnt.add(i);\n            }\n        }\n        // when the chars are exactly the same or there is only one pair of diff chars, check if swapping makes them equal then return true\n        return (cnt.size()==0) || ((cnt.size()==2) && (s1.charAt(cnt.elementAt(0))==s2.charAt(cnt.elementAt(1)) || s1.charAt(cnt.elementAt(1))==s2.charAt(cnt.elementAt(0))));\n    }\n}\n```\n\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case, **please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)
['C', 'C++', 'Java']