Solution in C#


  • 0
    P
        public string Convert(string s, int numRows) {
             if (s.Length == 0 || numRows < 2) return s;
                string ZigZag = "";
                int len = 2 * (numRows - 1);
                for (int i = 0; i < numRows; i++)
                {
                    for (int j = i; j < s.Length; j += len)
                    {
                        ZigZag += s[j];
                        if (i > 0 && i < numRows - 1)
                        {
                            if (j + len - 2 * i < s.Length)
                            {
                                ZigZag += s[j + len - 2 * i];
                            }
                        }
                    }
                }
                return ZigZag;
        }
    }'''

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.