Java two round of DP. Space O(M*N), Time O(M*N)
First loop, dp is for count of same substring starts from i and j. If s[i]==t[j], dp[i][j]=1+dp[i+1][j+1], otherwise 0.\n\nSecond loop, res is for count of targ
First loop, `dp` is for count of same substring starts from `i` and `j`. If `s[i]==t[j]`, `dp[i][j]=1+dp[i+1][j+1]`, otherwise `0`.\n\nSecond loop, `res` is for count of target substring with one diff starts from `i` and `j`. if `s[i]==t[j]`, `res[i][j]=res[i+1][j+1]`(add both to front of `res[i+1][j+1]`), otherwise is `res[i][j]=1+dp[i+1][j+1]`(add both to front of `dp[i+1][j+1]`, plus `1` for themself). Meanwhile `sum` of `res[i][j]` is the result.\n```\nclass Solution {\n    public int countSubstrings(String s, String t) {\n        var sl=s.length();\n        var tl=t.length();\n        var dp=new int[sl+1][tl+1];\n        for(var i=sl-1;i>=0;i--) {\n            for(var j=tl-1;j>=0;j--) {\n                if(s.charAt(i)==t.charAt(j)) dp[i][j]=1+dp[i+1][j+1];\n            }\n        }\n        \n        var res=new int[sl+1][tl+1];\n        var sum=0;\n        for(var i=sl-1;i>=0;i--) {\n            for(var j=tl-1;j>=0;j--) {\n                if(s.charAt(i)==t.charAt(j)) res[i][j]=res[i+1][j+1]; \n                else res[i][j]=1+dp[i+1][j+1];\n                sum+=res[i][j];\n            }\n        }\n        return sum;\n    }\n}\n```
[]