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

Commit b8b658b

Browse files
Create Find the Number of Ways to Place People II.java
1 parent 6792618 commit b8b658b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public int numberOfPairs(int[][] points) {
3+
Arrays.sort(points, (o1, o2) -> {
4+
int c = o1[0] - o2[0];
5+
if (c == 0) {
6+
return o2[1] - o1[1];
7+
}
8+
return c;
9+
});
10+
int result = 0;
11+
for (int i = 0; i < points.length; i++) {
12+
int[] point = points[i];
13+
int minX = point[0] - 1;
14+
int maxX = Integer.MAX_VALUE;
15+
int minY = Integer.MIN_VALUE;
16+
int maxY = point[1] + 1;
17+
for (int j = i + 1; j < points.length; j++) {
18+
int[] nextPoint = points[j];
19+
if (nextPoint[0] > minX && nextPoint[0] < maxX && nextPoint[1] > minY && nextPoint[1] < maxY) {
20+
result++;
21+
minX = nextPoint[0];
22+
minY = nextPoint[1];
23+
}
24+
}
25+
}
26+
return result;
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /