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 8d0b66b commit 3c27d63Copy full SHA for 3c27d63
String/ZigZag_Conversion.java
@@ -0,0 +1,30 @@
1
+//LeetCode 6. ZigZag Conversion
2
+//Question - https://leetcode.com/problems/zigzag-conversion/
3
+
4
+class Solution {
5
+ public String convert(String s, int numRows) {
6
+ StringBuffer res[] = new StringBuffer[numRows];
7
8
+ for(int i = 0 ; i < numRows ; i++){
9
+ res[i] = new StringBuffer();
10
+ }
11
12
+ int i = 0;
13
+ while(i < s.length()){
14
+ //going down
15
+ for(int ind = 0 ; ind < numRows && i < s.length() ; ind++){
16
+ res[ind].append(s.charAt(i++));
17
18
+ //going up
19
+ for(int ind = numRows - 2 ; ind >= 1 && i < s.length() ; ind--){
20
21
22
23
24
+ for(i = 1 ; i < numRows ; i++){
25
+ res[0].append(res[i]);
26
27
28
+ return res[0].toString();
29
30
+}
0 commit comments