回答編集履歴
2
computeIfAbsentの第二引数に誤り
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
// 記録
|
18
18
|
|
19
|
-
blocks.computeIfAbsent(x, HashSet<Integer>
|
19
|
+
blocks.computeIfAbsent(x, k -> new HashSet<Integer>()).add(y);
|
20
20
|
|
21
21
|
|
22
22
|
|
1
座標管理例
test
CHANGED
@@ -5,3 +5,23 @@
|
|
5
5
|
(1,2)や(2,1)にも「ある」という判定になってしまいます。
|
6
6
|
|
7
7
|
例えばx座標に対してブロックがあるy座標はどこかと対応付けて管理する必要があります。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```java
|
12
|
+
|
13
|
+
Map<Integer, Set<Integer>> blocks = new HashMap<>();
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
// 記録
|
18
|
+
|
19
|
+
blocks.computeIfAbsent(x, HashSet<Integer>::new).add(y);
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
// 判定
|
24
|
+
|
25
|
+
boolean isExist = blocks.getOrDefault(x, Collections.emptySet()).contains(y);
|
26
|
+
|
27
|
+
```
|