Skip to content

Commit

Permalink
Update ZigZagConversion.java
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam authored Oct 12, 2024
1 parent 46f8ae2 commit f91b90a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions java/ZigZagConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ enum Direction {
public String convert(String s, int numRows) {
StringBuilder result = new StringBuilder();

// Initialize the mapping
StringBuilder[] allRows = new StringBuilder[numRows];
for (int i = 0; i < numRows; i++) {
allRows[i] = new StringBuilder();
for (int depth = 0; depth < numRows; depth++) {
allRows[depth] = new StringBuilder();
}

// Build the mapping
helper(s, numRows, allRows, Direction.SOUTH, 0);

// Join the mapping strings together
for (int depth = 0; depth < numRows; depth++) {
result.append(allRows[depth].toString());
}
Expand Down

0 comments on commit f91b90a

Please sign in to comment.