Skip to content

392. Is Subsequence - #49

Open
akmhmgc wants to merge 1 commit into
mainfrom
392
Open

392. Is Subsequence#49
akmhmgc wants to merge 1 commit into
mainfrom
392

Conversation

@akmhmgc

@akmhmgc akmhmgc commented Oct 9, 2025

Copy link
Copy Markdown
Owner

解いた問題

392. Is Subsequence

使用言語

Ruby

次に解く問題

31. Next Permutation

@akmhmgc akmhmgc added the ruby label Oct 9, 2025
Comment thread 392/step2.md
def is_subsequence(s, t)
pattern = ""
s.each_char do |c|
pattern += ".*" + Regexp.escape(c)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pattern << ".*" + Regexp.escape(c) の方が自然でしょうか?

Comment thread 392/step3.md
def is_subsequence(s, t)
lcs_last_index = 0
t.each_char { |char| lcs_last_index += 1 if s[lcs_last_index] == char }
lcs_last_index == s.size

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lcsはlongest common subsequenceの略でしょうか?
s="abbbbbb", t="bbbbbb"みたいなときにa以降に進まないので、厳密には正しくない気がします。
checking_indexとかの方が自然ではないでしょうか。
ロジックはとても読みやすいです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants