id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string sol = \"\";\n vector<string> rows;\n for(int i=0; i<numRows; i++)\n rows.push_back(\"\");\n int row=0;\n if(numRows==1) return s;\n for(int i=0; i<s.size(); i++)\n {\n... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<vector<char>> arr(numRows + 1, vector<char>(0));\n int i = 0;\n while(i < s.size())\n {\n for(int j = 0; j < numRows; ++j)\n {\n if(i < s.size())\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) {\n return s;\n }\n vector<vector<char>> resultVec(numRows, vector<char>{});\n\n int index = 0;\n\n int rowIndex = 0;\n\n // 0 -> vertical\n // 1 -> cross\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n map<int,string>m;\n int k=0;\n int c=0;\n if(numRows==1 || numRows>=s.length()) return s;\n for(int i=0;i<s.size();i++){\n if(k<numRows && c==0){\n m[k]+=s[i];\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int idx = 0; int d=1;\n if (numRows == 1 || numRows >= s.length()) {\n return s;\n }\n vector<vector<char>> arr(numRows);\n for(auto c : s){\n arr[idx].push_back(c);\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n std::string convert(std::string s, int numRows) {\n if(numRows < 2) return s;\n int i = 0;\n std::string res{};\n //int arrSize = s.size() % numRows > 0 ? s.size() / numRows + 1 : s.size() / numRows;\n std::vector<std::vector<char>> arr;\n arr.reserve(n... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1 || numRows >= s.length())\n {\n return s;\n }\n vector<vector<char>> v(numRows);\n int i = 0, n = s.length(), k = 0, dir = 1;\n string st = \"\";\n while(i<n)... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<int>rows;\n int n=s.size();\n int i=0;\n int t=1;\n while(i<n)\n {\n t=1;\n while(t<=numRows)\n {\n rows.push_back(t);\n t++;\n i++;\n }... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<vector<int>> zig(numRows);\n int r = 0;\n int d = numRows > 1 ? 1 : 0;\n for(int i=0;i<s.size();i++){\n zig[r].push_back(s[i]);\n if(r == numRows - 1){\n d *= -1;... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n \n int n=s.size();\n if(numRows==1) return s;\n vector<string> vec;\n vector<int> idx;\n for(int i=0; i<n; i++) idx.push_back(i);\n for(int i=0; i<numRows; i++) vec.push_back(\"\");\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\r\npublic:\r\n string convert(string s, int numRows) {\r\n unsigned n = s.size();\r\n if (numRows == 1 || numRows >= n) {\r\n return s;\r\n }\r\n vector<vector<char>> rows(numRows);\r\n unsigned m = 2 * (numRows - 1);\r\n for (unsigned i = 0; i < n; i++) {\r\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n unordered_map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n unordered_map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int n) {\n if(n == 1) return s;\n string t = \"\";\n map<int, int> l, r;\n for(int d = 0; d < n; d++){\n l[d] = 2*(n-1-d);\n r[d] = 2*d;\n }\n for(int row = 0; row < n; row++){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n unordered_map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n unordered_map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n unordered_map<int, vector<char>> pattern;\n\n if (numRows == 1)\n {\n return s;\n }\n \n int i = 1;\n bool forward = true;\n for (const auto& ch : s)\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<string> buckets(numRows);\n\n vector<string*> round;\n for (auto i = 0; i < numRows; ++i) {\n round.emplace_back(&buckets[i]);\n }\n\n for (auto i = numRows - 2; i >= 1; --i) {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) {\n return s;\n }\n\n vector< vector<char> > rows;\n for(int i = 0; i < numRows; i++) {\n rows.push_back({});\n }\n\n int currentRow = 0;\n int di... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string result;\n if(numRows == 1 || s.size() <= numRows)\n return s;\n map<int, vector<char>>test;\n int reverse = 1;\n int begin = 0;\n for(int i = 0;i<s.size();i++)\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) \n {\n int size = s.size();\n \n if (numRows == 1 || numRows >= size) {\n return s; \n }\n\n int pairCol = numRows - 1;\n int charInPair = numRows + (pairCol - 1);\n int maxpa... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) \n {\n int size = s.size();\n \n if (numRows == 1 || numRows >= size) {\n return s; \n }\n\n int pairCol = numRows - 1;\n int charInPair = numRows + (pairCol - 1);\n int maxpa... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n unordered_map<int,vector<char>> cToRow;\n int count = 1;\n bool back = false;\n for(char c:s){\n cToRow[count].push_back(c);\n if(!back){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\nmap<int,vector<int>> mapps;\n string convert(string s, int numRows) {\n string ssols=\"\";\n int po=0;\n mapps[1].push_back(s[po]);\n po++;\n while(po<s.size()){\n for(int p=2;po<s.size()&&p+1<=numRows;p++){\n mapps[p].push_back(s[po]);\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\n const vector<pair<int, int>> directions{{0, 1}, {1, -1}};\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n vector<vector<char>> solution{};\n int direction = 0;\n int x = 0;\n int y = 0;\n for(char ch : s) {... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\n const vector<pair<int, int>> directions{{0, 1}, {1, -1}};\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n vector<vector<char>> solution{};\n int direction = 0;\n int x = 0;\n int y = 0;\n for(char ch : s) {... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int j = 0;\n vector<vector<char>> list(numRows);\n for( int i = 0; i < numRows; i++ ) {\n vector<char> iL ;\n list.push_back(iL);\n }\n int n = s.size();\n while(j < n) {... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n bool goRight = true;\n vector<vector<char>> m(1, vector<char>(numRows, '0'));\n\n size_t row = 0;\n size_t col = 0;\n\n for (char c : s) {\n m[row][col] = c;\n if (goRight && co... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "#define DEBUG 0\nclass Solution {\npublic:\n vector<vector<char>> createZigZagVector(int numRows)\n {\n vector<vector<char>> zigZagVector;\n vector<char> emptyCharVector;\n\n for (unsigned int i = 0; i < numRows; i++)\n {\n zigZagVector.push_back(emptyCharVector... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n int n = s.size();\n \n string ans = \"\";\n \n int k = 0;\n vector<vector<char>> temp;\n for(int i = 0; i < numRows*2 - 2; i++) {\n temp.p... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) return s; // Edge case for single row\n \n map<int, list<char>> noteit;\n short k = 1; // current row index\n bool down = true; // direction flag\n short i = 0;\n s... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, short numRows) {\n if (numRows == 1) return s; // Edge case for single row\n \n map<short, list<char>> noteit;\n int k = 1; // current row index\n int down = 1; // direction flag\n int i = 0;\n int n... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n \n map<int,vector<char>> mp;\n int size = s.length();\n int inc = 0;\n int val=0;\n for(int i=0;i<size;i++)\n {\n if(inc==0)\n {\n mp[val].push_back... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n \n map<int,vector<char>> mp;\n int size = s.length();\n int inc = 0;\n int val=0;\n for(int i=0;i<size;i++)\n {\n if(inc==0) // case 1 : going up to down\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1){\n return s;\n }\n map<int, vector<int>> h;\n int sign=1;\n int j=0;\n int i=1;\n while(s[j]!= '\\0'){\n h[i].push_back(s[j]);\n i+=sign;... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int index = 0;\n string a[numRows + 1];\n int r = 1;\n while(index < s.size())\n {\n if (r == numRows){\n a[numRows] += s[index];\n index ++;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1)\n return s;\n string res = \"\";\n int cycle = numRows + numRows - 2;\n\n for (int i = 0; i < s.size(); i += cycle) {\n res += s[i];\n }\n\n for (int ro... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string arr[numRows];\n for(int i=0;i<numRows;i++){\n arr[i]=\"\";\n }\n int i=0;\n while(i<s.length()){\n for(int j=0;j<numRows && i<s.length();j++){\n arr[j]=arr... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1)\n return s;\n vector<char> vchar;\n int cycle = numRows + numRows - 2;\n\n for (int i = 0; i < s.size(); i += cycle) {\n vchar.push_back(s[i]);\n }\n\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1){\n return s;\n }\n vector<vector<string>> table;\n int cur = 0;\n int zig = -1;\n int zcount = 0;\n string atom;\n for(int i = 0; i < numRows; i++){\n table.push_back(vector<stri... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows <= 1){\n return s;\n }\n\n unordered_set<int> visited;\n queue<int> toVisit;\n\n int gap = (numRows - 1) * 2;\n\n for(int i = 0; i < s.length() + (gap / 2); i += gap){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int n) {\n if (n == 1) {\n return s;\n }\n\n // first, last row = n - 2 = 2\n // 2nd = n - 3 = 1, n - 2 - (n - 3) - 1 = 0\n // 3nd = \n\n // 1 = 3, 0 = n - 1, n - (n - 1) - 1\n // 2 = 2, 1 = ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n map<int,vector<char>> mp;\n int n=s.length();\n int i=0;\n while(i<n)\n {\n int c=0;\n while(i<n && c<numRows)\n {\n mp[c].push_back(s[i]);\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string ret=\"\";\n unordered_map<int, vector<int>> rowToIndex;\n bool down=true;\n int count=0;\n for(int i=0;i<s.length();i++){\n string s2=s.substr(i,1);\n if(down){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<string> v(numRows);\n int i=0;\n int row=0;\n bool dir=true;\n int n=s.size();\n string ans=\"\";\n if(numRows==1) return s;\n while(true){\n if(dir){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1)\n {\n return s;\n }\n vector<string> v(numRows);\n int i = 0;\n int n = s.length();\n int j = 0;\n while(j < n)\n {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1){\n return s;\n }\n vector<string>arr(numRows);\n int row = 0;\n int i = 0;\n bool direction = true;\n while(true){\n if(direction){\n while(row < numR... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) \n {\n string ans;\n vector<string> temp(numRows,\"\");\n int j=0,i=0,size=s.size();\n while(j<size)\n {\n for(i=0;i<numRows;i++)\n {\n if(j>=size) break;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n unordered_map<int,list<char>> mp;\n int i = 0; bool flag = true;\n for(auto ch: s){\n if(flag) mp[i++].push_back(ch); \n else mp[i--].push_back(ch);\n\n if(i == numRows-1 || i == ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n void diagonal(string s, vector<vector<char>>& store, int &i, int &j, int& ind, int n){\n while(i >= 0 && ind < s.size()) store[i--][j++] = s[ind++];\n --j;\n i = 1;\n }\n void vertical(string s, vector<vector<char>>& store, int &i, int &j, int& ind,... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows <= 1){\n return s;\n }\n\n unordered_set<int> visited;\n queue<int> toVisit;\n\n int gap = (numRows - 1) * 2;\n\n for(int i = 0; i < s.length() + gap; i += gap){\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows <= 1) return s;\n string ans = \"\";\n \n vector<vector<char>> x(numRows);\n int i=0,k = 0;\n while(i<s.size()){\n while(k<numRows && i<s.size()){\n x[k].p... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1){\n return s;\n }\n\n vector<vector<char> >v(numRows);\n for (int i = 0; i < s.length();)\n {\n for (int j = 0; j < numRows-1 && i < s.length(); j++)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n string *ret = new string(s.length(),'a');\n if(numRows == 1 || numRows == s.length()){\n return s;\n }\n int colDis = numRows-2;\n int numCols = s.length()/(2*numRows-2)*(colDis+1)+s.leng... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) {\n return s;\n }\n\n std::vector<std::vector<char>> rows;\n rows.resize(numRows);\n\n int curr_row = 0;\n int curr_col = 0;\n std::string curr_dir = \"down... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<vector<char>> a(numRows);\n string solution;\n bool GoingUp = 0;\n int colHeight = 0;\n int rowHeight = -1;\n\n if(numRows == 1){\n return s;\n }\n\n for (auto... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n\n if( numRows == 1 )\n {\n return s;\n }\n\n vector<string> rows;\n for( int j = 0; j < numRows; j++ )\n {\n rows.push_back( \"\" );\n }\n\n int activeRow =... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int intRows) {\n int n=s.length();\n if(intRows==1)\n return s;\n int cols=0;\n while(n>0){\n n=n-intRows;\n cols++;\n if(n>0){\n n=n-(intRows-2);\n cols... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<vector<char>> result;\n int count = 0;\n int i = 0;\n for(; i < s.size(); ) {\n vector<char> cols(numRows,' ');\n \n if(count == 0 || count == numRows-1) {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows==1) return s;\n vector<string> res;\n for (int i=0;i<numRows;i++){\n res.push_back(\"\");\n }\n int down = 1; int row =0;\n res[row] = res[row]+s[0];row++;\n for ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n vector<vector<string>> row;\n for(int i = 0; i < numRows; i++) {\n vector<string> vec;\n row.push_back(vec);\n }\n int counter = 0;\n int isa... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s;\n vector<vector<string>> row;\n for(int i = 0; i < numRows; i++) {\n vector<string> vec;\n row.push_back(vec);\n }\n int counter = 0;\n int isa... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int n = s.size();\n vector<vector<char>> mat;\n mat.push_back(vector<char>{});\n for (int i = 0; i < n; i++) {\n if (mat.back().size()==numRows) { \n int new_col_count... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n\n if (numRows == 1) {\n return s;\n }\n\n vector<string> strcols;\n\n int cnt = 0, row = 0, col = 0;\n bool flag = true;\n string sub;\n for (size_t idx = 0; idx < s.size(); ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int r) {\n map<int,string> m;\n bool flag=true;\n int t=0;\n for(int i=0;i<s.size();i++){\n m[t]+=s[i];\n if(flag) t++;\n else t--;\n if(t==r-1) flag=false;\n if(t==0) ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n map<int,string> mpp;\n int row = 1;\n bool flag = true;\n for(int i=0; i<s.size(); i++){\n if(flag == true){\n mpp[row].push_back(s[i]);\n row++;\n }\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n const size_t N(s.size());\n if (numRows == 1)\n return s;\n int cols(0), idx(0);\n bool isCross(false);\n while (idx < N) {\n if (isCross) {\n idx += (numRows - 2... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1) return(s);\n int n=s.size();\n string ans=\"\";\n map<int,string> mp;\n for (int i = 0; i < numRows; ++i) {\n mp[i] =\"\";\n }\n bool flag=true;\n int t=0... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\nint noofclm(string s, int numRows) {\n if (numRows == 1) return s.size();\n int n = s.size();\n int clm = 0;\n bool flag = true;\n while (n > 0) {\n if (flag) {\n clm++;\n n -= numRows;\n f... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1) return s; // Handle edge case\n\n int n = s.size();\n int cycleLen = 2 * numRows - 2; // Calculate the length of a full cycle (zigzag)\n\n // Estimate the number of columns needed\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1 || s.size() <= numRows) return s;\n\n // Calculate Columns\n int zigzagNums = (s.size() / (2*numRows-2))+1;\n int numCols = zigzagNums*(numRows-1);\n vector<vector<char>> zigzag = vec... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1 || s.size() <= numRows) return s;\n\n // Calculate Columns\n int zigzagNums = (s.size() / (2*numRows-2))+1;\n int numCols = zigzagNums*(numRows-1);\n vector<vector<char>> zigzag = vec... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n std::string result_str = \"\";\n std::unordered_map<std::string,char> ch_row_column; \n int cur_row = 0, cur_column = 0; // row and column of the current character\n\n if (numRows==1||s.size()==1)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n std::string result_str = \"\";\n std::unordered_map<std::string,char> ch_row_column; \n int cur_row = 0, cur_column = 0; // row and column of the current character\n\n if (numRows==1||s.size()==1)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) {\n return s;\n }\n\n int sections = ceil(s.length() / (2 * numRows - 2.0));\n int numCols = sections * (numRows - 1);\n\n vector<vector<char>> matrix(numRows, vector<cha... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) {\n return s;\n }\n\n int n = int(s.size());\n int sections = ceil(n / (2 * numRows - 2.0));\n int numCols = sections * (numRows - 1);\n\n vector<vector<char>> mat... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\nstring convert(string s, int numRows) {\n if (numRows == 1) return s;\n\n // 1. Compute the size of 2D matrix\n int n = s.length();\n // each section has at most 2*rows-2 chars\n int sections = ceil(n / (2.0*numRows - 2));\n cout << \"sections = \" << sections <... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int num) {\n if (num == 1) return s;\n int n = s.length();\n int it = 0;\n int col = (n / (2 * num - 2) + 1) * (num - 1);\n int move = num - 2;\n int c = 0;\n bool ans = true;\n\n vector<vecto... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution\n{\npublic:\n string convert(string s, int numRows)\n {\n vector<ostringstream> lines(numRows);\n int row = 0;\n bool directionIsDown = true;\n for (char &c : s)\n {\n \n#ifdef DEBUG\n if (row != 0 && !directionIsDown)\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows <= 1) {\n return s;\n }\n \n vector<stringstream> rows(numRows);\n int i = 0;\n int dir = 1;\n for (char c : s) {\n rows[i] << c;\n if (i ==... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n void make_move(int &row, int &col, bool &isDiag, int numRows) {\n if (row == numRows - 1) {\n isDiag = 1;\n }\n if (row == 0){\n isDiag = 0;\n }\n if (isDiag == 0) {\n ++row;\n }\n else {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n void make_move(int &row, int &col, bool &isDiag, const int &numRows) {\n if (row == numRows - 1) {\n isDiag = 1;\n }\n if (row == 0){\n isDiag = 0;\n }\n if (isDiag == 0) {\n ++row;\n }\n el... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n stringstream zz;\n vector<stringstream> prev_row(numRows);\n int curr_row = 0;\n bool forward = true;\n\n if (numRows == 1) {\n return s;\n }\n\n for (int spos=0; spos<s.size... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "#include <string>\n#include <vector>\n\nclass Solution {\npublic:\n void create(string s,vector<vector<char>>& v, int row, int col, int index) {\n if (index >= s.size()) {\n return;\n }\n if (row == 0 && index < s.size()) {\n while (row < v.size()-1 && index... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n const vector<vector<int>>moves = { {0,1},{1,-1} };\nstring convert(string s, int numRows) {\n if (numRows == 1) return s;\n if (numRows == 2) {\n string result = \"\";\n for (int i = 0; i < s.size(); i += 2) result += s[i];\n for (int i = 1; i < s.s... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n vector<vector<char>> result;\n \n for (int i = 0; i < s.size();){\n int j = 0;\n vector<char> temp;\n while (j++ < numRows){\n if (i < s.size())\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows == 1){\n return s;\n }\n char** m = new char*[numRows];\n for (int i = 0; i < numRows; i++) {\n m[i] = new char[s.length()];\n }\n for (int i = 0; i < numRows; i++) {\n for (int j ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "struct ArrayPointer{\n int length;\n char *array; \n};\n\nclass Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1){return s;}\n int length=s.length();\n ArrayPointer A[numRows];\n for(int i=0;i<numRows;i++){\n A[i].length=0;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "struct ArrayPointer{\n int length;\n char *array; \n};\n\nclass Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1){return s;}\n int length=s.length();\n ArrayPointer A[numRows];\n for(int i=0;i<numRows;i++){\n A[i].length=0;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "struct ArrayPointer{\n int length;\n char *array; \n};\n\nclass Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1){return s;}\n int length=s.length();\n ArrayPointer A[numRows];\n for(int i=0;i<numRows;i++){\n A[i].length=0;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) {\n return s;\n }\n bool r_growing = true; \n // TODO(caml): need ceil of double\n // int num_cols = std::ceil(s.size() / (numRows + numRows - 2)) * (numRows - 1);\n int num_cols ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n void insert_row(string& ans, string s, int jump, int interval){\n for(int i = interval; i < s.size(); i += jump){\n ans.push_back(s[i]);\n // Add middle element for rows between the first and last row\n if (interval > 0 && interval < ju... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n char **mem=new char*[numRows];\n int *lens=new int[numRows]; \n for(int i=0;i<numRows;i++){\n mem[i]=new char[s.length()];\n lens[i]=0;\n }\n int row=0;\n int direction=-... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "struct rowGap {\n int first;\n int second;\n};\n\n/* 3:\n4, 0\n2, 2\n0, 4\n*/\n\n/* 4:\n6, 0\n4, 2\n2, 4\n0, 6\n*/\n\nclass Solution {\npublic:\n\n rowGap getRowGap(string s, int rowNum, int numRows) {\n if (numRows == 1) {\n return {.first = 0, .second = 1};\n } else {\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "#include <vector>\n#include <string>\n\nclass Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1) return s;\n string reserve = s;\n vector<string> myset;\n while(s.length()){\n if(s.length()<numRows) {\n string temp = s;... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "#include <iostream>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string convert(string s, int numRows) {\n // Edge case: if numRows is 1, return the string as no conversion is needed\n if (numRows == 1) return s;\n \n // Define 'f' as the length of ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n int i,j,k,g=2*(numRows-1),n=s.size();\n if (n==numRows || numRows==1) {\n return s;\n }\n string res;\n for (i=g,k=0;i>=0,k<numRows;i=i-2,k++) {\n int var=g-k*2,evenOdd;\n ... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1)\n return s;\n int length = s.length();\n string ans = \"\";\n for(int i=0;i<numRows;i++){\n int idx = i;\n int deltaSouth = 2 * (numRows-1-i);\n in... |
6 | <p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre>
P A H N
A P L S I I G
Y I R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"<... | 3 | {
"code": "class Solution {\npublic:\n string convert(string s, int numRows) { \n string all[numRows][s.size()];\n int row=0;\n int col=0;\n int cur=0;\n while(cur < s.size()){\n while(row < numRows && cur<s.size()){\n all[row++][col] = s[cur++];\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.