Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43420ac

Browse files
committedOct 17, 2021
add 2038
1 parent 82b3cfb commit 43420ac

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
1111
|2039|[The Time When the Network Becomes Idle](https://leetcode.com/problems/the-time-when-the-network-becomes-idle/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2039.java) ||Medium||
12+
|2038|[Remove Colored Pieces if Both Neighbors are the Same Color](https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2038.java) ||Medium||
1213
|2037|[Minimum Number of Moves to Seat Everyone](https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2037.java) ||Easy||
1314
|2034|[Stock Price Fluctuation](https://leetcode.com/problems/stock-price-fluctuation/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2034.java) ||Medium||
1415
|2033|[Minimum Operations to Make a Uni-Value Grid](https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2033.java) ||Medium||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2038 {
4+
public static class Solution1 {
5+
public boolean winnerOfGame(String colors) {
6+
int ans = 0;
7+
for (int i = 1; i < colors.length() - 1; i++) {
8+
if (colors.charAt(i) == colors.charAt(i - 1) && colors.charAt(i) == colors.charAt(i + 1)) {
9+
if (colors.charAt(i) == 'A') {
10+
ans++;
11+
} else {
12+
ans--;
13+
}
14+
}
15+
}
16+
return ans > 0;
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2038;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2038Test {
10+
private static _2038.Solution1 solution1;
11+
private static String color;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _2038.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
color = "AAABABB";
21+
assertEquals(true, solution1.winnerOfGame(color));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)
Failed to load comments.