We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
There was an error while loading. Please reload this page.
1 parent 0b88964 commit a3f28baCopy full SHA for a3f28ba
solution/0000-0099/0097.Interleaving String/Solution.go
@@ -0,0 +1,23 @@
1
+func isInterleave(s1 string, s2 string, s3 string) bool {
2
+ if len(s1)+len(s2) != len(s3) {
3
+ return false
4
+ }
5
+ n,m := len(s1), len(s2)
6
+ dp := make([][]bool, n+1)
7
+ for i := 0; i < len(dp); i++ {
8
+ dp[i] = make([]bool, m+1)
9
10
+ dp[0][0] = true
11
+ for i := 1; i <= n; i++ {
12
+ dp[i][0] = dp[i-1][0] && (s1[i-1] == s3[i-1])
13
14
+ for i := 1; i <= m ; i++ {
15
+ dp[0][i] = dp[0][i-1] && (s2[i-1] == s3[i-1])
16
17
18
+ for j := 1; j <= m; j++ {
19
+ dp[i][j] = dp[i-1][j] && (s1[i-1] == s3[i-1+j]) || dp[i][j-1] && (s2[j-1] == s3[i+j-1])
20
21
22
+ return dp[n][m]
23
+}
0 commit comments