From 9c12265ede94f4ff72bf1eaaae5cfed496ab8ae1 Mon Sep 17 00:00:00 2001 From: philip82148 <92205270+philip82148@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:05:47 +0900 Subject: [PATCH] add 1.cpp --- 01-15/7.Is Subsequence/1.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 01-15/7.Is Subsequence/1.cpp diff --git a/01-15/7.Is Subsequence/1.cpp b/01-15/7.Is Subsequence/1.cpp new file mode 100644 index 0000000..0f69e46 --- /dev/null +++ b/01-15/7.Is Subsequence/1.cpp @@ -0,0 +1,34 @@ +#if __has_include("../debug.hpp") +#include "../debug.hpp" +#endif +// ここまでローカルでのデバッグ用なので気にしないでください -------------------- + +#include + +using namespace std; + +// <時間> +// 1分 +// <感想> +// <疑問・不安点(・個人的な感想、違う意見があれば教えてほしいもの)> +// - 20行目の後に改行を入れるかどうか +// - indexの命名をこだわるか迷った。 +// 他の候補としてはsiとか(sのイテレータみたいな)。 +// リーダブルコードあったが、これは複数イテレータがあったときに +// 区別しやすいという話なので今回はしなかった + +// なお以下で出てくるコメントはプロダクト版にも書くつもりのコメント +class Solution { + public: + bool isSubsequence(string s, string t) { + if (s.size() == 0) return true; + int index = 0; + for (auto c : t) { + if (s[index] == c) { + ++index; + if (index == s.size()) return true; + } + } + return false; + } +};