class Solution {
public:
string convert(string s, int nRows) {
stringstream str;
if(nRows==1) return s;
for(int i=0;i<nRows;i++)
{
int j=i;
while(j<s.length())
{
str<<s[j];
if(i!=0&&i!=nRows-1&&j+(nRows-i-1)*2<s.length())
str<<s[j+(nRows-i-1)*2];
j=j+(nRows-1)*2;
}
}
str>>s;
return s;
}
};
leetcode ZigZag Conversion
最新推荐文章于 2021-11-05 22:58:08 发布