Skip to content

Commit a3f28ba

Browse files
committed
feat: add golang solution for leetcode 0097
1 parent 0b88964 commit a3f28ba

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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+
for i := 1; i <= n; i++ {
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

Comments
 (0)