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

Commita992800

Browse files
Create 6-Zigzag-Conversion.java
1 parenta5c9cf4 commita992800

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎java/6-Zigzag-Conversion.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//We check whether we are at the diagonal or not using a boolean and increment the pointer accordingly.
2+
3+
classSolution {
4+
publicStringconvert(Strings,introw) {
5+
if (row==1)returns;
6+
StringBuildersb =newStringBuilder();
7+
for (inti =0;i<row;i++) {
8+
intj =i;
9+
if (i==0 ||i==row-1) {
10+
while (j<s.length()) {
11+
sb.append(s.charAt(j));
12+
j +=2*(row-1);
13+
}
14+
}else {
15+
booleandiagonal =false;
16+
while (j<s.length()) {
17+
if (!diagonal) {
18+
sb.append(s.charAt(j));
19+
j+=2*(row-i-1);
20+
diagonal =true;
21+
}else {
22+
sb.append(s.charAt(j));
23+
j+=2*i;
24+
diagonal =false;
25+
}
26+
}
27+
}
28+
}
29+
returnsb.toString();
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp