Movatterモバイル変換


[0]ホーム

URL:


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

Commit6fffa99

Browse files
committed
Create 0097-interleaving-string.go
1 parentc1f03e5 commit6fffa99

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎go/0097-interleaving-string.go‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
varcachemap[[2]int]bool
2+
varst1string
3+
varst2string
4+
varst3string
5+
6+
funcisInterleave(s1string,s2string,s3string)bool {
7+
iflen(s1)+len(s2)!=len(s3) {
8+
returnfalse
9+
}
10+
cache=make(map[[2]int]bool)
11+
st1=s1
12+
st2=s2
13+
st3=s3
14+
returndfs(0,0)
15+
}
16+
17+
funcdfs(i,jint)bool {
18+
ifi>=len(st1)&&j>=len(st2) {
19+
returntrue
20+
}
21+
22+
val,ok:=cache[[2]int{i,j}]
23+
24+
ifok {
25+
returnval
26+
}
27+
28+
ifi<len(st1)&&st1[i]==st3[i+j]&&dfs(i+1,j) {
29+
returntrue
30+
}
31+
ifj<len(st2)&&st2[j]==st3[i+j]&&dfs(i,j+1) {
32+
returntrue
33+
}
34+
35+
cache[[2]int{i,j}]=false
36+
returnfalse
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp