Java | BruteForce | Explained
\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        List<String> subStrings = new ArrayList<>();\n        List<String> subStringt=
```\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        List<String> subStrings = new ArrayList<>();\n        List<String> subStringt= new ArrayList<>();\n        \n\t\t//generate all possible substrings of both the given string\n        generateSubString(s,subStrings);\n        generateSubString(t,subStringt);\n        \n        int count = 0;\n        \n\t\t//(i)compare each substring of s with each substring of n.\n        for(String ss : subStrings){\n            for(String st: subStringt){\n                int diff = 0;\n\t\t//if lengths of both the substring(s and t) are equal then further compare each character of both sub strings.\t\t\n                if(ss.length() == st.length()){\n                    for(int i=0; i<ss.length();i++){\n\t\t\t\t\t//the difference between both the sub strings should be 1 character.\n                        if(ss.charAt(i)!=st.charAt(i))\n                            diff++;\n                        //if difference between both the sub string is more than 1 character than no need to check further.\n                        if(diff > 1)  break;\n                    }\n\t\t\t\t //if difference between both the sub string is one then consider it as answer, and look for more possible answers.\t\n                    if(diff==1) count++;\n                }\n            }\n            \n        }\n        return count;\n        }\n    \n    private void generateSubString(String s, List<String> list){\n        int window = 0;\n        \n        while(window<s.length()){\n            \n        for(int i=0; i+window<s.length(); i++){\n            list.add(s.substring(i,i+window+1));\n         }\n            window++;\n        }\n    }\n}\n```\n\n**Upvote if you like the solution.**
['Java']