Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17-InSange #64

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
=======
---
35 changes: 35 additions & 0 deletions InSange/λ¬Έμžμ—΄/6_Zigzag Conversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
string convert(string s, int numRows) {
if (numRows <= 1 || s.size() <= numRows) return s;

vector<string>v(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;
}
};