-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion6.java
More file actions
35 lines (35 loc) · 740 Bytes
/
question6.java
File metadata and controls
35 lines (35 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public String convert(String s, int numRows) {
String mat[]=new String[numRows];
int l=s.length();
int i=0,k=0;
String ans="";
for(i=0;i<numRows;i++)
{
mat[i]="";
}
i=0;
while(i<l)
{
for(k=0;k<numRows;k++)
{
if(i>=l)
break;
mat[k]=mat[k]+s.charAt(i);
i++;
}
for(k=numRows-2;k>0;k--)
{
if(i>=l)
break;
mat[k]=mat[k]+s.charAt(i);
i++;
}
}
for(i=0;i<numRows;i++)
{
ans=ans+mat[i];
}
return ans;
}
}