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

Commit06b5ac6

Browse files
add 1576
1 parent468013a commit06b5ac6

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-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+
|1576|[Replace All ?'s to Avoid Consecutive Repeating Characters](https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1576.java)||String|Easy|
1112
|1574|[Shortest Subarray to be Removed to Make Array Sorted](https://leetcode.com/problems/shortest-subarray-to-be-removed-to-make-array-sorted/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1574.java)||Array, Binary Search|Medium|
1213
|1572|[Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1572.java)||Array|Easy|
1314
|1567|[Maximum Length of Subarray With Positive Product](https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1567.java)|[:tv:](https://youtu.be/bFer5PdsgpY)|Greedy|Medium|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1576 {
4+
publicstaticclassSolution1 {
5+
publicStringmodifyString(Strings) {
6+
StringBuildersb =newStringBuilder();
7+
for (inti =0;i <s.length();i++) {
8+
charc =s.charAt(i);
9+
if (c =='?') {
10+
charreplacement =findReplacement(sb,i,s);
11+
sb.append(replacement);
12+
}else {
13+
sb.append(c);
14+
}
15+
}
16+
returnsb.toString();
17+
}
18+
19+
privatecharfindReplacement(StringBuildersb,intindex,Strings) {
20+
charreplacement ='a';
21+
if (index >0) {
22+
intcount =1;
23+
while (replacement ==sb.charAt(index -1)) {
24+
replacement +=count %26;
25+
}
26+
}
27+
if (index +1 <s.length()) {
28+
intcount =1;
29+
while (replacement ==s.charAt(index +1) || (index >0 &&replacement ==sb.charAt(index -1))) {
30+
replacement +=count %26;
31+
}
32+
}
33+
returnreplacement;
34+
}
35+
}
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1576;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1576Test {
10+
privatestatic_1576.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1576.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals("azs",solution1.modifyString("?zs"));
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp