public String convert(String s, int numRows) {
if(s==null || numRows<=1 ||numRows>=s.length()) return s;
int l=s.length();
StringBuilder sb=new StringBuilder();
for(int i=0;i<numRows;i++){
int j=i;
while(j<l){
sb.append(s.charAt(j));
if((i!=0) && (i!=numRows-1) && ((j+(numRows-1-i)*2)<l)) sb.append(s.charAt(j+(numRows-1-i)*2));
j+=(numRows-1)*2;
}
}
return sb.toString();
}
Let's snipe the Leetcode problems together. No more hiding! Leetcode solution in Java! Your comments and suggestions are welcome!
Friday, May 5, 2017
LeetCode 2nd time 6. ZigZag Conversion Leetcode Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment