其他分享
首页 > 其他分享> > asa

asa

作者:互联网

点击查看代码
package Com.Xu.String;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Six {
    public static String convert(String s, int numRows) {
        if(numRows==1){
            return s;
        }
        List<StringBuilder> rows=new ArrayList<>();
        for(int i=0;i< Math.min(numRows,s.length());i++){
            rows.add(new StringBuilder());
        }
        int curRow=0;
        boolean goingDown=false;
        for(Character c:s.toCharArray()){
            rows.get(curRow).append(c);
            if(curRow==0||curRow==numRows-1){
                goingDown=!goingDown;
            }
            curRow+=goingDown?1:-1;
        }
        StringBuilder ret=new StringBuilder();
        for(StringBuilder row:rows){
            ret.append(row);
        }
        return ret.toString();
    }

    public static void main(String[] args) {
        String s="ABCD";
        System.out.println(convert(s,3));
    }
}

标签:rows,String,goingDown,StringBuilder,numRows,asa,curRow
来源: https://www.cnblogs.com/liyangXu/p/15916112.html