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

Commitd948bb6

Browse files
add 1652
1 parent2394b41 commitd948bb6

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-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+
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java)||Easy|Array|
1112
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java)||Easy|Array, Sort|
1213
|1637|[Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/)|[Javascript](./javascript/_1637.js)|| Medium| Sort|
1314
|1636|[Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1636.java)||Easy|Array, Sort|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1652 {
4+
publicstaticclassSolution1 {
5+
publicint[]decrypt(int[]code,intk) {
6+
int[]result =newint[code.length];
7+
intlen =code.length;
8+
if (k ==0) {
9+
for (inti =0;i <code.length;i++) {
10+
result[i] =0;
11+
}
12+
}elseif (k >0) {
13+
intkSum =0;
14+
for (inti =1;i <=k;i++) {
15+
kSum +=code[i];
16+
}
17+
result[0] =kSum;
18+
for (inti =1;i <len;i++) {
19+
kSum -=code[i];
20+
kSum +=code[(i +k) %len];
21+
result[i] =kSum;
22+
}
23+
}else {
24+
intkSum =0;
25+
intkVal =Math.abs(k);
26+
for (inti =len -1;i >=len -kVal;i--) {
27+
kSum +=code[i];
28+
}
29+
result[0] =kSum;
30+
for (inti =1;i <len;i++) {
31+
kSum -=code[(len -kVal +i -1) %len];
32+
kSum +=code[i -1];
33+
result[i] =kSum;
34+
}
35+
}
36+
returnresult;
37+
}
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1652;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertArrayEquals;
8+
9+
publicclass_1652Test {
10+
privatestatic_1652.Solution1solution1;
11+
privatestaticint[]code;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1652.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
code =newint[]{5,7,1,4};
21+
assertArrayEquals(newint[]{12,10,16,13},solution1.decrypt(code,3));
22+
}
23+
24+
@Test
25+
publicvoidtest2() {
26+
code =newint[]{1,2,3,4};
27+
assertArrayEquals(newint[]{0,0,0,0},solution1.decrypt(code,0));
28+
}
29+
30+
@Test
31+
publicvoidtest3() {
32+
code =newint[]{2,4,9,3};
33+
assertArrayEquals(newint[]{12,5,6,13},solution1.decrypt(code, -2));
34+
}
35+
36+
@Test
37+
publicvoidtest4() {
38+
code =newint[]{10,5,7,7,3,2,10,3,6,9,1,6};
39+
assertArrayEquals(newint[]{22,26,22,28,29,22,19,22,18,21,28,19},solution1.decrypt(code, -4));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp