标签:ring length append ++ return logs turn zigzag while
class Solution { public: string convert(string s, int numRows) { if (numRows == 1){ return s; } string out; for (int i = 0; i < numRows; ++i){ int j = 0; while (true){ int pos = -1; if (j % 2 == 0){ pos = j * (numRows - 1) + i; } else if (i != 0 && i != numRows - 1) { pos = j * (numRows - 1) + numRows - i - 1; } if (pos >= (int)s.length()){ break; } if (pos >= 0){ out.append(1, s[pos]); } j ++; } } return out; } };
leetcode problem 6: zigzag word
标签:ring length append ++ return logs turn zigzag while
原文地址:http://www.cnblogs.com/nosaferyao/p/7502840.html