add: 220122-CN

This commit is contained in:
Lam Haoyin 2022-01-22 08:42:13 +08:00
parent 3056c6223d
commit 314628c295
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 17 additions and 1 deletions

16
2201/220122-CN.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <string>
#include <iostream>
class Solution {
public:
static int removePalindromeSub(const std::string& s) {
auto r = s;
std::reverse(r.begin(), r.end());
return 1 + (!(s == r) && std::count_if(s.begin(), s.end(), [&](char c) { return c == (s[0] ^ 3); }) ? 1 : 0);
}
};
int main() {
std::cout << Solution::removePalindromeSub("abaaba");
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(2201)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2201 220121.cpp) ADD_EXECUTABLE(2201 220122-CN.cpp)