448 B
448 B
C++ Tricks
Rotate String Check string trick search
Front
How to check if string s can be rotated to match string goal in O(n)?
Back
bool rotateString(string s, string goal) {
return s.size() == goal.size() && (s + s).find(goal) != string::npos;
}
If goal is a substring of s + s, then s can be rotated to match goal.