diff --git a/InSange/README.md b/InSange/README.md index 5d27a2a..ebdf8af 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -17,6 +17,7 @@ | 13차시 | 2024.05.22 | BFS | [특정 거리의 도시 찾기](https://www.acmicpc.net/problem/18352) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/53)] | 14차시 | 2024.05.27 | 투 포인터 | [포도주 시음](https://www.acmicpc.net/problem/31589) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/56)] | 15차시 | 2024.05.27 | 정렬 | [통나무 건너뛰기](https://www.acmicpc.net/problem/11497) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/57)] -| 16차시 | 2024.06.28 | 그래프 | [Maximum_Total_Importance_ofRoads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/57)] +| 16차시 | 2024.06.28 | 그래프 | [Maximum_Total_Importance_ofRoads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/63)] +| 17차시 | 2024.06.28 | 문자열 | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion/) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/64)] ======= --- diff --git "a/InSange/\353\254\270\354\236\220\354\227\264/6_Zigzag Conversion.cpp" "b/InSange/\353\254\270\354\236\220\354\227\264/6_Zigzag Conversion.cpp" new file mode 100644 index 0000000..d019c73 --- /dev/null +++ "b/InSange/\353\254\270\354\236\220\354\227\264/6_Zigzag Conversion.cpp" @@ -0,0 +1,35 @@ +#include +#include + +using namespace std; + +class Solution { +public: + string convert(string s, int numRows) { + if (numRows <= 1 || s.size() <= numRows) return s; + + vectorv(numRows, ""); + + int i, j, dir; + j = 0; + dir = -1; + + for (i = 0; i < s.size(); i++) + { + if (j == numRows - 1 || j == 0) dir *= -1; + v[j] += s[i]; + if (dir == 1) j++; + else j--; + } + + string answer; + answer = ""; + + for (auto c : v) + { + answer += c; + } + + return answer; + } +}; \ No newline at end of file