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

Commitb3bcc5b

Browse files
add 2103
1 parent9e0f0d6 commitb3bcc5b

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.HashSet;
5+
importjava.util.Map;
6+
importjava.util.Set;
7+
8+
publicclass_2103 {
9+
publicstaticclassSolution1 {
10+
publicintcountPoints(Stringrings) {
11+
Map<Integer,Set<Integer>>map =newHashMap<>();
12+
for (inti =0;i <rings.length() -1;i +=2) {
13+
charcolor =rings.charAt(i);
14+
intpos =Character.getNumericValue(rings.charAt(i +1));
15+
Set<Integer>set =map.getOrDefault(pos,newHashSet<>());
16+
if (color =='R') {
17+
set.add(1);
18+
}elseif (color =='G') {
19+
set.add(2);
20+
}else {
21+
set.add(3);
22+
}
23+
map.put(pos,set);
24+
}
25+
intans =0;
26+
for (intpos :map.keySet()) {
27+
if (map.get(pos).size() ==3) {
28+
ans++;
29+
}
30+
}
31+
returnans;
32+
}
33+
}
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2103;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2103Test {
10+
privatestatic_2103.Solution1solution1;
11+
privatestaticintexpected;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_2103.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
expected =1;
21+
assertEquals(expected,solution1.countPoints("B0B6G0R6R0R6G9"));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp