寻找每一个规律


  • 0
    C

    class Solution {
    public String convert(String s, int numRows) {
    if(numRows==1) return s;

        char[] results=s.toCharArray();
    	  String str = "";
        
    	  int tmp=numRows;
        
    	  for(int i =0;i<numRows;i++,tmp--){
    	  int inc=i;
          int count=0;
    	  while(inc<s.length()){
    	  str+=results[inc];
              if(tmp==numRows){
                inc+=2*(tmp-1);
              }
    	  else if(tmp>1){
              if(count%2==0){
                    inc+=2*(tmp-1);
              count++;
              }
              else{
                  inc+=(numRows-tmp)*2;
                  count++;
              }
          }
    	  else if(tmp==1)
    		  inc+=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.