392. Is Subsequence#7
Conversation
713a29e to
9c12265
Compare
| // なお以下で出てくるコメントはプロダクト版にも書くつもりのコメント | ||
| class Solution { | ||
| public: | ||
| bool isSubsequence(string s, string t) { |
There was a problem hiding this comment.
s, t はどっちがどっちか分からないので避けたいですね。以下、Chrome での例。
def is_subsequence(containing, contained):static bool isSubsequence(const field_names &Seq, const field_names &Subseq)https://source.chromium.org/chromium/infra/infra_superproject/+/main:build/recipes/recipe_modules/chromium_tests/tests/api/set_swarming_test_execution_info.py?q=is.%3Fsubsequence
https://source.chromium.org/chromium/infra/infra_superproject/+/main:build/recipes/recipe_modules/chromium_orchestrator/tests/api/trybot_steps.py?q=is.%3Fsubsequence
https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/extensions/cxx_debugging/third_party/llvm/src/clang/unittests/AST/RandstructTest.cpp?q=is.%3Fsubsequence
There was a problem hiding this comment.
ありがとうございます!LeetCodeに与えられたものなので気にしてなかったですが、確かにちゃんとした方が良いですね。
リファレンスくださりありがとうございます!
| } | ||
| return false; | ||
| } | ||
| }; |
There was a problem hiding this comment.
こんな感じになりました、、
// <時間>
// 10分
// <感想>
// <疑問・不安点(・個人的な感想、違う意見があれば教えてほしいもの)>
// なお以下で出てくるコメントはプロダクト版にも書くつもりのコメント
class Solution {
public:
bool isSubsequence(string sub, string s) {
int s_i = 0;
for (int sub_i = 0; sub_i < sub.size(); ++sub_i) {
while (s_i < s.size() && s[s_i] != sub[sub_i]) ++s_i;
if (s_i == s.size()) return false;
++s_i;
}
return true;
}
};There was a problem hiding this comment.
そうですね。他の人の解法を探すとこれも出てきたと思います。
引数の型は const string& にするかもしれません。
There was a problem hiding this comment.
初見時、s_i と sub_i を空目したので、string sub, string targetとかにして、s_i, t_i などにしたほうが読みやすいと思いました
|
この問題、他にも解き方の表現に幅があると思うで、Discordを漁ってみると良さそうです(例えば、subをqueueにつめて、一文字ずつ消して最終的に空になったらOKなど) 他の人の、自分だったら選ばなさそうな解法を読んで、なんでこう考えるのかを見るのも自分は勉強になったと思います |
注意
ファイルが複数ある場合、<番号>.cppの<番号>が最も大きいものが最新版です!
最新版のみレビューお願いします!(もちろん過去のものをレビューしていただいても構いませんmm)
問題
https://leetcode.com/problems/is-subsequence/description/?envType=problem-list-v2&envId=xo2bgr0r