class Solution { public: string convert(string s, int numRows) { if(numRows == 1){ return s; } vectorres(numRows);//res的大小为非空行数大小 int i = 0; int flag = -1; for(char c:s){ res[i] += c; if(i == 0 || i == numRows -1){ flag = -flag;//行数逆转 } i += flag; } string new_s; for(string r:res){ new_s += r; } return new_s; } };
参考链接:
https://leetcode-cn.com/problems/zigzag-conversion/solution/zzi-xing-bian-huan-by-jyd/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)