// Algorithm / 演算法:
// 與 C 版本相同的雙指針/貪心策略，改用 std::string 的 size() 取得長度。
// Same two-pointer greedy as the C version, using std::string::size() for lengths.

#include <string>   // 引入 std::string / brings in std::string

class Solution {
public:
    // const std::string& 用「常數參考」傳入，避免拷貝且承諾不修改 / pass by const reference: no copy, read-only
    bool isSubsequence(const std::string& s, const std::string& t) {
        size_t i = 0;                          // s 的指針 / pointer into s
        size_t j = 0;                          // t 的指針 / pointer into t
        const size_t n = s.size();             // s.size() 是 O(1) 取得長度 / O(1) length lookup on std::string
        const size_t m = t.size();             // t 的長度 / length of t

        // 同時兩個指針都還沒越界時繼續 / continue while both indices are in bounds
        while (i < n && j < m) {
            // s[i] 與 t[j] 都回傳該位置的 char / both subscripts return the char at that position
            if (s[i] == t[j]) {
                ++i;                           // 前置 ++：先加 1 再使用，效果同 i++ / pre-increment: same effect as i++
            }
            ++j;                               // t 每一步都前進 / always advance j
        }

        return i == n;                         // 全部 s 都吃光就成功 / success iff every char of s was consumed
    }
};
