commit c1f56d362048716e92433a99382f513ff8bd68b4 parent 83bdd225a53198c231a454ddc875e7cc9da7c109 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Fri, 3 Feb 2023 01:43:11 +0100 Daily Problem Diffstat:
A | Problems/0006.cpp | | | 18 | ++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/0006.cpp b/Problems/0006.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + string convert(string s, int numRows) { + if (numRows == 1) return s; + vector<string> mat(numRows); + + int mode = 1, x = 0; + for (char c : s) { + mat[x].push_back(c); + x += mode; + if (x == numRows - 1 || x == 0) mode *= -1; + } + + string res = ""; + for (const auto &r : mat) res += r; + return res; + } +}; diff --git a/README.md b/README.md @@ -26,6 +26,7 @@ for solving problems. | 0001 | Easy | [Two Sum](Problems/0001.cpp) | | 0002 | Medium | [Add Two Numbers](Problems/0002.cpp) | | 0003 | Medium | [Longest Substring Without Repeating Characters](Problems/0003.cpp) | +| 0006 | Medium | [Zigzag Conversion](Problems/0006.cpp) | | 0011 | Medium | [Container With Most Water](Problems/0011.cpp) | | 0012 | Medium | [Integer to Roman](Problems/0012.cpp) | | 0013 | Easy | [Roman to Integer](Problems/0013.cpp) |