-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is Subsequence #19
base: main
Are you sure you want to change the base?
Is Subsequence #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//lint:file-ignore U1000 Ignore all unused code | ||
package issubsequence | ||
|
||
/* | ||
時間:10分 | ||
思っていたよりも時間がかかってしまった。 | ||
*/ | ||
func isSubsequenceStep1(s string, t string) bool { | ||
current := 0 | ||
for i := 0; i < len(s); i++ { | ||
for { | ||
if current >= len(t) { | ||
return false | ||
} | ||
if s[i] == t[current] { | ||
current++ | ||
break | ||
} | ||
current++ | ||
} | ||
} | ||
return true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//lint:file-ignore U1000 Ignore all unused code | ||
package issubsequence | ||
|
||
/* | ||
よりシンプルにした。 | ||
*/ | ||
func isSubsequenceStep2(s string, t string) bool { | ||
if len(s) == 0 { | ||
return true | ||
} | ||
current := 0 | ||
for i := 0; i < len(t); i++ { | ||
if s[current] == t[i] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currentだとあんまり情報量がない気もするので、こっちもsi, ti(Goではこういう感じで省略するんでしたっけ?)でいいかもです |
||
current++ | ||
} | ||
if current == len(s) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//lint:file-ignore U1000 Ignore all unused code | ||
package issubsequence | ||
|
||
/* | ||
おそらくこれが一番シンプルなのではないだろうか。 | ||
*/ | ||
func isSubsequenceStep3(s string, t string) bool { | ||
i, j := 0, 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for文の外でも使うなら |
||
for i < len(s) && j < len(t) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if s[i] == t[j] { | ||
i++ | ||
} | ||
j++ | ||
} | ||
return i == len(s) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/stdtypes.html#str.find
Python の .find(sub, start) 相当のものがあるといいですが、なさそうですね。
https://pkg.go.dev/strings#Index
というように時々標準ライブラリーを調べておくといいです。