fix: further simplify
This commit is contained in:
parent
56bace58b7
commit
7e99751414
|
|
@ -3,18 +3,9 @@
|
|||
class Solution {
|
||||
public:
|
||||
static bool rotateString(const std::string& s, const std::string& goal) {
|
||||
char ch = s[0];
|
||||
std::size_t n = s.length();
|
||||
|
||||
auto verify = [&](std::size_t p) {
|
||||
for (std::size_t i = 0; i < n; ++i, p = (1 + p) % n)
|
||||
if (s[i] != goal[p])
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
for (std::size_t nextPos = goal.find(ch, 0); nextPos != std::string::npos; nextPos = goal.find(ch, nextPos + 1))
|
||||
if (verify(nextPos))
|
||||
const std::size_t n = s.length();
|
||||
for (std::size_t np = goal.find(s[0], 0); np != std::string::npos; np = goal.find(s[0], np + 1))
|
||||
if (goal.substr(0, np) == s.substr(n - np) && goal.substr(np) == s.substr(0, n - np))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue