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.
2 parents 242d09a + 270095d commit b122d2aCopy full SHA for b122d2a
solution/006.ZigZag Conversion/Solution.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public String convert(String s, int numRows) {
3
+ if (numRows == 1) return s;
4
+ StringBuilder result = new StringBuilder();
5
+ int group = 2 * numRows - 2;
6
+ for (int i = 1; i <= numRows; i++) {
7
+ int interval = 2 * numRows - 2 * i;
8
+ if (i == numRows) interval = 2 * numRows - 2;
9
+ int index = i;
10
+ while (index <= s.length()) {
11
+ result.append(s.charAt(index - 1));
12
+ index += interval;
13
+ interval = group - interval;
14
+ if (interval == 0) interval = group;
15
+ }
16
17
+ return result.toString();
18
19
+}
0 commit comments