本文共 846 字,大约阅读时间需要 2 分钟。
结束条件:遍历完所有行
class Solution {public: string convert(string s, int numRows) { if (numRows <= 1 || s.length() <= numRows) return s; string convertion; for (int i = 0; i < numRows; ++i){ for (int j = i; j < s.length(); j += 2*(numRows-1)){ convertion += s[j]; if (i != 0 && i != numRows-1){ int k = j + 2*(numRows-1) - 2*i; if (k < s.length()){ convertion += s[k]; } } } } return convertion; }};
转载地址:http://njpbb.baihongyu.com/