Skip to content

Commit

Permalink
Merge pull request #64 from AlgoLeadMe/17-InSange
Browse files Browse the repository at this point in the history
17-InSange
  • Loading branch information
InSange authored Jul 10, 2024
2 parents 75fb02d + af245f5 commit 9e7dc6e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
| 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/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;
}
};

0 comments on commit 9e7dc6e

Please sign in to comment.