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

Commite22d545

Browse files
add 1544
1 parent777f9dc commite22d545

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-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+
|1544|[Make The String Great](https://leetcode.com/problems/make-the-string-great/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1544.java)||Easy|String, Stack|
1112
|1541|[Minimum Insertions to Balance a Parentheses String](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1541.java)||Medium|String, Stack|
1213
|1539|[Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1539.java)||Easy|Array, HashTable|
1314
|1535|[Find the Winner of an Array Game](https://leetcode.com/problems/find-the-winner-of-an-array-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1535.java)|[:tv:](https://youtu.be/v6On1TQfMTU)|Medium|Array|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Stack;
4+
5+
publicclass_1544 {
6+
publicstaticclassSolution1 {
7+
publicStringmakeGood(Strings) {
8+
Stack<Character>stack =newStack<>();
9+
for (inti =0;i <s.length() -1;i++) {
10+
charc =s.charAt(i);
11+
if (stack.isEmpty()) {
12+
stack.add(c);
13+
}else {
14+
if (Character.toLowerCase(stack.peek()) ==Character.toLowerCase(c)) {
15+
if ((Character.isLowerCase(stack.peek()) &&Character.isUpperCase(c))) {
16+
stack.pop();
17+
}elseif (Character.isUpperCase(stack.peek()) &&Character.isLowerCase(c)) {
18+
stack.pop();
19+
}else {
20+
stack.add(c);
21+
}
22+
}else {
23+
stack.add(c);
24+
}
25+
}
26+
}
27+
charc =s.charAt(s.length() -1);
28+
if (!stack.isEmpty() &&Character.toLowerCase(stack.peek()) ==Character.toLowerCase(c)) {
29+
if ((Character.isLowerCase(stack.peek()) &&Character.isUpperCase(c))) {
30+
stack.pop();
31+
}elseif (Character.isUpperCase(stack.peek()) &&Character.isLowerCase(c)) {
32+
stack.pop();
33+
}else {
34+
stack.add(c);
35+
}
36+
}else {
37+
stack.add(c);
38+
}
39+
StringBuildersb =newStringBuilder();
40+
while (!stack.isEmpty()) {
41+
sb.append(stack.pop());
42+
}
43+
returnsb.reverse().toString();
44+
}
45+
}
46+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1544;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1544Test {
10+
privatestatic_1544.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1544.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals("leetcode",solution1.makeGood("leEeetcode"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals("",solution1.makeGood("abBAcC"));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals("s",solution1.makeGood("s"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp