add: 0344

This commit is contained in:
Lam Haoyin 2022-02-16 23:56:26 +08:00
parent 2d3e268d3e
commit 491c957eee
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 25 additions and 1 deletions

24
more/0344.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <vector>
class Solution {
public:
static void reverseString(std::vector<char>& s) {
char tmp;
for (int i = 0, j = s.size() - 1; i < j; ++i, --j) {
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
}
};
int main() {
const char str[] = "hello";
std::vector<char> args;
args.reserve(sizeof str);
for (auto i : str)
if (i)
args.push_back(i);
Solution::reverseString(args);
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(more)
SET(CMAKE_CXX_STANDARD 23) SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(more 0100.cpp) ADD_EXECUTABLE(more 0344.cpp)