Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b3bcc5b

Browse files
add 2103
1 parent 9e0f0d6 commit b3bcc5b

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-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+
|2103|[Rings and Rods](https://leetcode.com/problems/rings-and-rods/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2103.java) ||Easy||
1112
|2099|[Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2099.java) ||Easy||
1213
|2095|[Delete the Middle Node of a Linked List](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2095.java) ||Medium||
1314
|2094|[Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2094.java) ||Easy||
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.HashSet;
5+
import java.util.Map;
6+
import java.util.Set;
7+
8+
public class _2103 {
9+
public static class Solution1 {
10+
public int countPoints(String rings) {
11+
Map<Integer, Set<Integer>> map = new HashMap<>();
12+
for (int i = 0; i < rings.length() - 1; i += 2) {
13+
char color = rings.charAt(i);
14+
int pos = Character.getNumericValue(rings.charAt(i + 1));
15+
Set<Integer> set = map.getOrDefault(pos, new HashSet<>());
16+
if (color == 'R') {
17+
set.add(1);
18+
} else if (color == 'G') {
19+
set.add(2);
20+
} else {
21+
set.add(3);
22+
}
23+
map.put(pos, set);
24+
}
25+
int ans = 0;
26+
for (int pos : map.keySet()) {
27+
if (map.get(pos).size() == 3) {
28+
ans++;
29+
}
30+
}
31+
return ans;
32+
}
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2103;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2103Test {
10+
private static _2103.Solution1 solution1;
11+
private static int expected;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _2103.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
expected = 1;
21+
assertEquals(expected, solution1.countPoints("B0B6G0R6R0R6G9"));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)