From dc1f0c4c0096013799416664894c5194dc7e1f52 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- works/solutions/leetcode/cpp/6.cpp | 56 -------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 works/solutions/leetcode/cpp/6.cpp (limited to 'works/solutions/leetcode/cpp/6.cpp') diff --git a/works/solutions/leetcode/cpp/6.cpp b/works/solutions/leetcode/cpp/6.cpp deleted file mode 100644 index f1d947c..0000000 --- a/works/solutions/leetcode/cpp/6.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -using std::string; - -class Solution -{ -public: - string convert(string s, int numRows) - { - if (numRows == 1) - return s; - - const auto length = s.size(); - const int count_per_group = numRows * 2 - 2; - string result; - result.reserve(length); - for (int row = 0; row < numRows; row++) - { - if (row == 0) - { - for (int p = 0; p < length; p += count_per_group) - result += s[p]; - } - else if (row == numRows - 1) - { - for (int p = row; p < length; p += count_per_group) - result += s[p]; - } - else - { - bool former = true; - const auto former_gap = count_per_group - row * 2; - const auto latter_gap = count_per_group - former_gap; - for (int p = row; p < length; p += (former ? former_gap : latter_gap), former = !former) - result += s[p]; - } - } - return result; - } -}; - -int main() -{ - Solution s; - - auto result1 = s.convert("PAYPALISHIRING", 3); - auto result2 = s.convert("PAYPALISHIRING", 4); - std::cout - << s.convert("A", 1) << '\n' - << result1 << '\n' - << "PAHNAPLSIIGYIR\n" - << result2 << '\n' - << "PINALSIGYAHRPI\n"; - return 0; -} \ No newline at end of file -- cgit v1.2.3