Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a3f28ba

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

File tree

1 file changed

+23
-0
lines changed
  • solution/0000-0099/0097.Interleaving String

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /