| 1 | package Medium; |
| 2 | |
| 3 | public class zigzag |
| 4 | { |
| 5 | public static void main(String[] args) |
| 6 | { |
| 7 | String s = "PAYPALISHIRING"; |
| 8 | int numRows = 1; |
| 9 | |
| 10 | System.out.println(convert(s, numRows)); |
| 11 | |
| 12 | } |
| 13 | |
| 14 | public static String convert(String s, int numRows) { |
| 15 | |
| 16 | if(numRows==1) |
| 17 | return s; |
| 18 | |
| 19 | String result = ""; |
| 20 | |
| 21 | for(int i=0;i<numRows;i++) |
| 22 | { |
| 23 | int j =i; |
| 24 | int flag = 1; |
| 25 | while(j<s.length()) |
| 26 | { |
| 27 | result+=s.charAt(j); |
| 28 | |
| 29 | if(i==0 || i==numRows-1) |
| 30 | { |
| 31 | j+=(numRows-1)*2; |
| 32 | } |
| 33 | else if(flag%2!=0) |
| 34 | { |
| 35 | j+=(numRows-1)*2-(2*i); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | j+=(2*i); |
| 40 | } |
| 41 | flag++; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return result; |
| 46 | |
| 47 | } |
| 48 | } |
| 49 |
nothing calls this directly
no outgoing calls
no test coverage detected