Leetcode006 ZigZag Conversion

 /* simple simulation algorithm
* we cann`t make sure the size of the string,
* so it had better to storage in vector.
* show[] to buffer the new order of the string
*/
class Solution {
public:
string convert(string s, int numRows) {
string result;
vector<char> show[numRows];
for(int index=;index<s.size();) //divide into two parts
{
for(int i=;i<numRows;i++) //simple row full storage
{
show[i].push_back(s[index++]);
if(index==s.size())break;
}
for(int i=;i<=numRows-;i++) //middle row only only one char storaged
{
for(int j=numRows-;j>=;j--)
{
if(i+j==numRows-)show[j].push_back(s[index++]);
if(index==s.size())break;
}
if(index==s.size())break;
}
}
for(int i=;i<numRows;i++)
{
for(int j=;j<show[i].size();j++)result+=show[i][j];
}
return result;
}
};
上一篇:Kubernetes Ingress 学习


下一篇:自然语言交流系统 phxnet团队 创新实训 项目博客 (九)