forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_356.java
31 lines (29 loc) · 948 Bytes
/
_356.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _356 {
public static class Solution1 {
/**
* credit: https://discuss.leetcode.com/topic/48172/simple-java-hashset-solution
*/
public boolean isReflected(int[][] points) {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
Set<String> set = new HashSet<>();
for (int[] point : points) {
max = Math.max(max, point[0]);
min = Math.min(min, point[0]);
String str = point[0] + "a" + point[1];
set.add(str);
}
int sum = max + min;
for (int[] p : points) {
String str = (sum - p[0]) + "a" + p[1];
if (!set.contains(str)) {
return false;
}
}
return true;
}
}
}