We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9c0ddc4 commit b369d12Copy full SHA for b369d12
java/006_ZigZag_Conversion.java
@@ -1 +1,33 @@
1
-//TODO
+//006_ZigZag_Conversion.java
2
+class Solution {
3
+ public String convert(String s, int numRows) {
4
+ if(numRows==1) {
5
+ return s;
6
+ }
7
+
8
+ String answer = "";
9
+ String[] str_array = new String[numRows];
10
11
+ for(int i=0;i<numRows;i++){
12
+ str_array[i]="";
13
14
15
+ int mod = 2*numRows-2;
16
17
+ for(int i=0;i<s.length();i++){
18
+ char c = s.charAt(i);
19
+ int index = i%mod;
20
+ if(index >= numRows) {
21
+ index = 2*(numRows-1) - index;
22
23
+ str_array[index]+=c;
24
25
26
27
+ answer += str_array[i];
28
29
30
+ return answer;
31
32
+}
33
0 commit comments