From 491c957eee5fe433143074551046d7a192738ae1 Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Wed, 16 Feb 2022 23:56:26 +0800 Subject: [PATCH] add: 0344 --- more/0344.cpp | 24 ++++++++++++++++++++++++ more/CMakeLists.txt | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 more/0344.cpp diff --git a/more/0344.cpp b/more/0344.cpp new file mode 100644 index 0000000..43d15da --- /dev/null +++ b/more/0344.cpp @@ -0,0 +1,24 @@ +#include + +class Solution { +public: + static void reverseString(std::vector& 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 args; + args.reserve(sizeof str); + for (auto i : str) + if (i) + args.push_back(i); + Solution::reverseString(args); + return 0; +} \ No newline at end of file diff --git a/more/CMakeLists.txt b/more/CMakeLists.txt index c2102a4..1241580 100644 --- a/more/CMakeLists.txt +++ b/more/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(more) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(more 0100.cpp) +ADD_EXECUTABLE(more 0344.cpp)