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

Commitea8e990

Browse files
add 848
1 parent09c7200 commitea8e990

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ _If you like this project, please leave me a star._ ★
502502
|856|[Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_856.java) | |Medium| Stack, String
503503
|852|[Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_852.java)||Easy|
504504
|849|[Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_849.java)||Easy|
505+
|848|[Shifting Letters](https://leetcode.com/problems/shifting-letters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_848.java) | |Medium| Array, String
505506
|844|[Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_844.java)||Easy|
506507
|841|[Keys and Rooms](https://leetcode.com/problems/keys-and-rooms/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_841.java) | |Easy|DFS, Graph
507508
|840|[Magic Squares In Grid](https://leetcode.com/problems/magic-squares-in-grid/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_840.java)||Easy|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_848 {
4+
publicstaticclassSolution1 {
5+
publicStringshiftingLetters(Strings,int[]shifts) {
6+
long[]preSums =newlong[shifts.length];
7+
for (inti =shifts.length -1;i >=0;i--) {
8+
if (i <shifts.length -1) {
9+
preSums[i] =preSums[i +1] +shifts[i];
10+
}else {
11+
preSums[i] =shifts[i];
12+
}
13+
preSums[i] %=26;
14+
}
15+
StringBuildersb =newStringBuilder();
16+
for (inti =0;i <s.length();i++) {
17+
intnewChar =s.charAt(i) + (int)preSums[i] %26;
18+
if (newChar >122) {
19+
sb.append((char) (newChar -122 +96));
20+
}else {
21+
sb.append((char) (newChar));
22+
}
23+
}
24+
returnsb.toString();
25+
}
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._848;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_848Test {
10+
privatestatic_848.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_848.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals("rpl",solution1.shiftingLetters("abc",newint[]{3,5,9}));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals("gfd",solution1.shiftingLetters("aaa",newint[]{1,2,3}));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals("rul",solution1.shiftingLetters("ruu",newint[]{26,9,17}));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals("wqqwlcjnkphhsyvrkdod",solution1.shiftingLetters("mkgfzkkuxownxvfvxasy",newint[]{505870226,437526072,266740649,224336793,532917782,311122363,567754492,595798950,81520022,684110326,137742843,275267355,856903962,148291585,919054234,467541837,622939912,116899933,983296461,536563513}));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp