ZigZag_Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);

解题思路:暴力解决....把字符串按照要求排一遍

 

class Solution {
    public String convert(String s, int numRows) {
        String str="";
		int len=s.length();
        if(numRows==1)
            return s;
        else
        {
         int i=0;
		int x=0;
		int y=0;
		int flag=0;
	    char ch[][]=new char[len][numRows];	
        while(i0&&flag==1&&i0)
					str=str+String.valueOf(ch[k][j]);
				
				}					
			}
		return 	str;   
}
		
    }
}

 

你可能感兴趣的:(【LeetCode】)