-
Notifications
You must be signed in to change notification settings - Fork 0
Create 392. Is Subsequence.md #54
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
Open
fuga-98
wants to merge
1
commit into
main
Choose a base branch
from
392.-Is-Subsequence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # 進め方 | ||
|
|
||
| Step1 : 問題を解く。 | ||
|
|
||
| Step2 : 他の人のPRを参照し、コメントする。 | ||
|
|
||
| Step3 : 3回続けてエラーが出ないように書く。ドキュメントを参照する。 | ||
|
|
||
| # 実践 | ||
|
|
||
| ## Step1 | ||
|
|
||
| ### 思考ログ | ||
|
|
||
| ```python | ||
| class Solution: | ||
| def isSubsequence(self, s: str, t: str) -> bool: | ||
| if not s: | ||
| return True | ||
| s_index = 0 | ||
| for char in t: | ||
| if char != s[s_index]: | ||
| continue | ||
| s_index += 1 | ||
| if s_index == len(s): | ||
| return True | ||
| return False | ||
| ``` | ||
|
|
||
| sが空のケースを忘れた。 | ||
| O(N) | ||
|
|
||
| ## Step2 | ||
|
|
||
| ### 同じ問題を解いた人のプルリクを見る | ||
|
|
||
| https://github.com/olsen-blue/Arai60/pull/58/files | ||
|
|
||
| > char は C/C++ で予約語のため、チーム内に C++ を書く方がいる場合は避けたほうが無難だと思います。 c または ch が良いかもしれません。 | ||
| > | ||
| - その視点はあまりありませんでした。 | ||
|
|
||
| > 何がいいたかったかというと、このあたりの変形を通して、他のやつと同じになります。 | ||
| > | ||
|
|
||
| > 変形の仕方も頭において、どう書くと見通しがよく伝わるかを考えてみましょう。 | ||
| > | ||
| - 変形の仕方は考えたほうがよさそう。 | ||
|
|
||
| https://github.com/hroc135/leetcode/pull/52 | ||
|
|
||
| - 二分探索でも解けるみたい。 | ||
|
|
||
| https://github.com/usatie/leetcode/pull/5/files | ||
|
|
||
| - 副作用について気にしないのは不安に感じました。 | ||
| - あえて分かりにくい解法で解くの私はあまり好きではないですね。 | ||
|
|
||
| ```python | ||
| class Solution: | ||
| def isSubsequence(self, s: str, t: str) -> bool: | ||
| assert s is not None | ||
| s_index = 0 | ||
| t_index = 0 | ||
| while s_index < len(s): | ||
| if t_index >= len(t): | ||
| return False | ||
| if s[s_index] == t[t_index]: | ||
| s_index += 1 | ||
| t_index += 1 | ||
| return True | ||
| ``` | ||
|
|
||
| このwhileが一番シンプルな感じがする。 | ||
|
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. はい、見やすいと思います。 |
||
|
|
||
| ## Step3 | ||
|
|
||
| ### 3回連続で再現 | ||
|
|
||
| ```python | ||
| class Solution: | ||
| def isSubsequence(self, s: str, t: str) -> bool: | ||
| s_i = 0 | ||
| t_i = 0 | ||
| while s_i < len(s): | ||
| if t_i >= len(t): | ||
| return False | ||
| if s[s_i] == t[t_i]: | ||
| s_i += 1 | ||
| t_i += 1 | ||
| return True | ||
| ``` | ||
|
|
||
| indexをiとしたが許容される気がする。 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
局所的な変形で見通しを良くするというのはよくやることかと思います。
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.
振り返ってみると三回書くフェーズで自然に思いつく気がします。