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

Commit989aa67

Browse files
add 2075
1 parentdfa38c9 commit989aa67

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2075|[Decode the Slanted Ciphertext](https://leetcode.com/problems/decode-the-slanted-ciphertext/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2075.java)||Medium||
1112
|2074|[Reverse Nodes in Even Length Groups](https://leetcode.com/problems/reverse-nodes-in-even-length-groups/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2074.java)||Medium||
1213
|2073|[Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2073.java)||Easy||
1314
|2070|[Most Beautiful Item for Each Query](https://leetcode.com/problems/most-beautiful-item-for-each-query/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2070.java)||Medium||
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_2075 {
4+
publicstaticclassSolution1 {
5+
publicStringdecodeCiphertext(StringencodedText,introws) {
6+
if (rows ==1) {
7+
returnencodedText;
8+
}
9+
inttotal =encodedText.length();
10+
intcols =total /rows;
11+
char[][]grid =newchar[rows][cols];
12+
intindex =0;
13+
for (inti =0;i <rows;i++) {
14+
for (intj =0;j <cols;j++) {
15+
grid[i][j] =encodedText.charAt(index++);
16+
}
17+
}
18+
StringBuildersb =newStringBuilder();
19+
intcolIndex =0;
20+
while (colIndex <cols) {
21+
for (intj =colIndex,i =0;j <cols &&i <rows;j++,i++) {
22+
sb.append(grid[i][j]);
23+
}
24+
colIndex++;
25+
}
26+
inti =sb.length() -1;
27+
while (i >=0 &&sb.charAt(i) ==' ') {
28+
i--;
29+
}
30+
returnsb.substring(0,i +1);
31+
}
32+
}
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2075;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2075Test {
10+
privatestatic_2075.Solution1solution1;
11+
privatestaticStringencodedText;
12+
privatestaticintrows;
13+
privatestaticStringexpected;
14+
15+
@BeforeClass
16+
publicstaticvoidsetup() {
17+
solution1 =new_2075.Solution1();
18+
}
19+
20+
@Test
21+
publicvoidtest1() {
22+
encodedText ="ch ie pr";
23+
rows =3;
24+
expected ="cipher";
25+
assertEquals(expected,solution1.decodeCiphertext(encodedText,rows));
26+
}
27+
28+
@Test
29+
publicvoidtest2() {
30+
encodedText ="iveo eed l te olc";
31+
rows =4;
32+
expected ="i love leetcode";
33+
assertEquals(expected,solution1.decodeCiphertext(encodedText,rows));
34+
}
35+
36+
@Test
37+
publicvoidtest3() {
38+
encodedText ="coding";
39+
rows =1;
40+
expected ="coding";
41+
assertEquals(expected,solution1.decodeCiphertext(encodedText,rows));
42+
}
43+
44+
@Test
45+
publicvoidtest4() {
46+
encodedText =" b ac";
47+
rows =2;
48+
expected =" abc";
49+
assertEquals(expected,solution1.decodeCiphertext(encodedText,rows));
50+
}
51+
52+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp