// Algorithm / 演算法:同 C 版本 / same as the C version.
// 1. 長度不等 → false / unequal lengths → false.
// 2. 構造 s+s,檢查 goal 是否為其子字串 / build s+s, test if goal is a substring.

#include <string>   // std::string 與其成員函式 / for std::string and its methods

class Solution {
public:
    // 用 const string& 接收參數,避免複製整個字串 / pass by const reference to avoid copying.
    bool rotateString(const std::string& s, const std::string& goal) {
        if (s.size() != goal.size()) return false;   // 長度檢查必不可少 / length must match first

        // s + s 直接用運算子重載完成串接,結果是新的 std::string
        // operator+ on std::string concatenates and returns a new string.
        std::string doubled = s + s;

        // find 回傳第一次出現的索引,沒找到回傳特殊常數 string::npos
        // find returns the index of the first occurrence, or string::npos if not found.
        return doubled.find(goal) != std::string::npos;
    }
};
