1
var countSubstrings = function (s, t) {2
const count1 = countAllSubstr(s);3
const count2 = countAllSubstr(t);7
for (const [substr1, freq1] of count1) {8
for (const [substr2, freq2] of count2) {9
if (differByOneChar(substr1, substr2)) {17
function countAllSubstr(str) {19
const count = new Map();21
for (let i = 0; i < n; i++) {23
for (let j = i; j < n; j++) {24
substr += str.charAt(j);26
if (!count.has(substr)) count.set(substr, 0);27
count.set(substr, count.get(substr) + 1);34
function differByOneChar(str1, str2) {35
if (str1.length != str2.length) return false;37
const n = str1.length;41
for (let i = 0; i < n; i++) {42
const char1 = str1.charAt(i);43
const char2 = str2.charAt(i);45
if (char1 != char2) missed++;47
if (missed > 1) return false;