share my java solution!


  • 0
    T
    public class Solution {
        public String convert(String s, int numRows) {
            
            String str="";
            if(numRows==1||numRows==0) return s;
            
            for(int i=0;i<numRows;i++){
                int k=0;
               for(int j=i;j<s.length();k++){
                 str=str+s.charAt(j);
                 
                 if(i!=0&&i!=numRows-1){
                     if(k%2==0)
                         j=2*(numRows-1-i)+j;
                      else
                         j=i*2+j;
                   }
                 else
                      j=j+2*(numRows-1);
                 
                      
                
                 }
               
            }
            return str;
        }
    }
    

Log in to reply
 

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