add: 220407-CN [cpp]
This commit is contained in:
parent
99ed7a5980
commit
e81c48f739
|
|
@ -0,0 +1,22 @@
|
|||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
std::size_t pos = 0;
|
||||
for (std::size_t nextPos = goal.find(ch, pos); nextPos != std::string::npos; nextPos = goal.find(ch, pos = nextPos + 1))
|
||||
if (verify(nextPos))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2204)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2204 220406-CN.cpp)
|
||||
ADD_EXECUTABLE(2204 220407-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue