[Java] Brute Force: Generating All Substrings
\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        Map<String, Integer> substrs = new HashMap<>();\n        Map<String, Integer> 
```\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        Map<String, Integer> substrs = new HashMap<>();\n        Map<String, Integer> substrs2 = new HashMap<>();\n        for (int i = 0; i < s.length(); i++) {\n            StringBuilder sb = new StringBuilder();\n            for (int j = i; j < s.length(); j++) {\n                sb.append(s.charAt(j));\n                String cur = sb.toString();\n                substrs.merge(cur, 1, Integer::sum);\n            }\n        }\n        for (int i = 0; i < t.length(); i++) {\n            StringBuilder sb = new StringBuilder();\n            for (int j = i; j < t.length(); j++) {\n                sb.append(t.charAt(j));\n                String cur = sb.toString();\n                substrs2.merge(cur, 1, Integer::sum);\n            }\n        }\n        int res = 0;\n        for (String substr : substrs.keySet()) {\n            char[] arr = substr.toCharArray();\n            for (int i = 0; i < arr.length; i++) {\n                for (char ch = \'a\'; ch <= \'z\'; ch++) {\n                    if (arr[i] != ch) {\n                        char temp = arr[i];\n                        arr[i] = ch;\n                        String cur = new String(arr);\n                        res += substrs2.containsKey(cur) ? substrs.get(substr) * substrs2.get(cur) : 0;\n                        arr[i] = temp;\n                    }\n                }\n            }\n        }\n        return res;\n    }\n}\n```
[]