An solution


  • 0
    H
    public class Solution {
        public string Convert(string s, int numRows) {
            if (s == null) s = "";
            if (numRows == 0) numRows = 1;
            string[] aRows = new string[numRows];
            for (int i = 0; i < numRows; i++) aRows[i] = "";
            int aRowNo = 0, aDerict = 0;
            for (int i = 0; i < s.Length; i++) {
                aRows[aRowNo] += s[i];
                if (aDerict == 0) { aRowNo++; }else { aRowNo--; }
                if (aRowNo > numRows - 1) aRowNo = numRows - 1;
                if (aRowNo < 0) aRowNo = 0;
                if (aRowNo == 0) aDerict = 0;
                if (aRowNo == numRows - 1) aDerict = 1;
            }
            string aResult = "";
            for (int i = 0; i < numRows; i++) aResult += aRows[i];
            return aResult;
        }
    }
    

Log in to reply
 

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