Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5474b4f

Browse files
Update 0006-zigzag-conversion.java
1 parentf3f0e71 commit5474b4f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎java/0006-zigzag-conversion.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
classSolution {
2+
publicStringconvert(Strings,intnumRows) {
3+
if (numRows ==1)
4+
returns;
5+
6+
StringBuilderres =newStringBuilder();
7+
intincrement =2 * (numRows -1);
8+
9+
for (intr =0;r <numRows;r++) {
10+
for (inti =r;i <s.length();i +=increment) {
11+
res.append(s.charAt(i));
12+
if (r >0 &&r <numRows -1 &&i +increment -2 *r <s.length()) {
13+
res.append(s.charAt(i +increment -2 *r));
14+
}
15+
}
16+
}
17+
returnres.toString();
18+
}
19+
}
20+
--------------------------------------------------------------------------------------------------------------------------
121
//We check whether we are at the diagonal or not using a boolean and increment the pointer accordingly.
222

323
classSolution {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp