Skip to content

Create 392. Is Subsequence.md#25

Merged
Mike0121 merged 3 commits intomainfrom
392.-Is-Subsequence
Nov 1, 2025
Merged

Create 392. Is Subsequence.md#25
Mike0121 merged 3 commits intomainfrom
392.-Is-Subsequence

Conversation

@Mike0121
Copy link
Copy Markdown
Owner

@Mike0121 Mike0121 commented Jun 7, 2024

Comment on lines 9 to 20
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちら s に番兵を追加して for ループを回し、最後に番兵に到達しているかどうかを返すという実装方法もありそうです。
その場合、if s == "": の条件分岐と for 文中の if s_index == len(s): の条件が不要になるので、コードとしてはシンプルに書けそうに思いました。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。なるほどと思いました。
追記してコミットしてみましたので、よければ一目見ていただける嬉しいです。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメント時に想定していたものとほぼ同じでした、よさそうです。参考までに僕のコードも載せておきます。(for ループか while ループかの違いだけですが)

class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        s += "#"
        s_index = 0
        for t_index in range(len(t)):
            if t[t_index] == s[s_index]:
                s_index += 1
        return s[s_index] == "#"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。よかったです。

Mike0121 added 2 commits June 8, 2024 17:29
関数型(っぽい)、番兵の追加の解法を追記
@Mike0121 Mike0121 merged commit 7251fff into main Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants