6. ZigZag Conversion

class Solution {
    public String convert(String s, int numRows) {
        if(numRows==1)
            return s;
        int divisor=(numRows-1)*2;
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<numRows;i++)
            for(int j=0;j<s.length();j++)
                if(j%divisor==i||j%divisor==divisor-i)
                    sb.append(s.charAt(j));
        return sb.toString();
    }
}

 

posted @ 2017-09-22 01:53  Weiyu Wang  阅读(85)  评论(0编辑  收藏  举报