leetcode6

public class Solution {
    public string Convert(string s, int numRows) {
        char[] c = s.ToArray();
            int len = c.Length;
            StringBuilder[] sb = new StringBuilder[numRows];
            for (int i = 0; i < sb.Length; i++)
            {
                sb[i] = new StringBuilder();
            }
            int j = 0;
            while (j < len)
            {
                for (int idx = 0; idx < numRows && j < len; idx++) // vertically down
                    sb[idx].Append(c[j++]);
                for (int idx = numRows - 2; idx >= 1 && j < len; idx--) // obliquely up
                    sb[idx].Append(c[j++]);
            }
            for (int idx = 1; idx < sb.Length; idx++)
                sb[0].Append(sb[idx]);
            return sb[0].ToString();
    }
}

https://leetcode.com/problems/zigzag-conversion/#/description

原文地址:https://www.cnblogs.com/asenyang/p/6817624.html