【leetCode】6_Z字型变换

class Solution {
    public String convert(String s, int numRows) {
        String ans = "";
        int length = s.length();
        for (int i = 0; i < numRows; i ++){
            int j = i;
            int count = 0;
            while (j < length){
                ans = ans.concat(new String(new char[]{s.charAt(j)}));
                if (numRows == 1)
                    j += 1;
                else if (i != numRows - 1 && (i == 0 || count % 2 == 0))
                    j += 2 * (numRows - i - 1);
                else
                    j += 2 * (i);
                count ++;
            }
        }
        return ans;
    }
}

 

你可能感兴趣的:(leetCode)