超巧妙的重复子串解决方法
虽然是一道简单题,但是有一种超巧妙的解决方法
class Solution {
public:
bool repeatedSubstringPattern(string s) {
string t = s + s;
t.erase(t.begin()); t.erase(t.end() - 1); // 掐头去尾
if (t.find(s) != std::string::npos) return true; // 检测是否还存在那个子串
return false;
}
};