❇ count-substrings-that-differ-by-one-character Images👌 🏆O(1)❤️ Javascript🎯 Memory👀80.45%🕕 ++Ex
\nTime Complexity: O(N^3)\nSpace Complexity: O(1)\n\n\n\n\n\nLogic:\n1. Initialize a counter cnt to 0.\n2. Loop through each character in the substring.\n3. Com
\nTime Complexity: O(N^3)\nSpace Complexity: O(1)\n\n```\n\n\n\nLogic:\n1. Initialize a counter cnt to 0.\n2. Loop through each character in the substring.\n3. Compare characters from str1 and str2.\n4. If characters differ, increment the mismatch counter.\n5. If there is more than 1 mismatch, return Infinity.\n6. Return the mismatch count.\n\nfunction numberOfMismatch(str1, str2, str1Index, str2Index, count) {\n    let cnt = 0;\n    for (let index = 0; index < count; index++) {\n        if (str1[str1Index + index] !== str2[str2Index + index]) {\n            if (cnt === 1) {\n                return Infinity;\n            }\n            cnt++;\n        }\n    }\n    return cnt;\n}\n\n\nLogic:\n\n1. Initialize a counter cnt to 0.\n2. Loop through all possible starting indices for substrings in str1 and str2.\n3. Use numberOfMismatch to check if substrings have exactly one mismatch.\n4. Increment cnt if exactly one mismatch is found.\n5. Return the count of such substrings.\n\nfunction compareString(str1, str2, count) {\n    let cnt = 0;\n    for (let str1Index = 0; str1Index <= str1.length - count; str1Index++) {\n        for (let str2Index = 0; str2Index <= str2.length - count; str2Index++) {\n            if (numberOfMismatch(str1, str2, str1Index, str2Index, count) === 1) {\n                cnt++;\n            }\n        }\n    }\n    return cnt;\n}\n\nvar countSubstrings = function (str1, str2) {\n    let count = 0;\n    for (let index = 0; index < str1.length; index++) {\n        count += compareString(str1, str2, index + 1);\n    }\n    return count;\n};\n```\n\n![image](https://assets.leetcode.com/users/images/9a54bca4-fc53-4acc-ab5d-b3c02f1f790d_1720706065.8514032.png)\n
['String', 'JavaScript']