Java without Stringbuilder


  • 0
    Z

    public String convert(String s, int numRows) {
    if(numRows==0)return s;
    int len =s.length();
    int diff = 2numRows-2;
    int count=1,n=0;
    String res ="";
    while(res.length()<len){
    n=count-1;
    while(n<len) {
    res=res.concat(s.charAt(n)+"");
    n+=diff;
    if(2
    count-1>count&&(n-(2count-2))<len&&count!=numRows) {
    res=res.concat(s.charAt(n-(2
    count-2))+"");
    }
    }
    count++;
    }
    return res;
    }


Log in to reply
 

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