We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6442928 commit cbdf34bCopy full SHA for cbdf34b
Easy/Points That Intersect With Cars.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public int numberOfPoints(List<List<Integer>> coordinates) {
3
+ coordinates.sort(Comparator.comparingInt((List<Integer> o) -> o.get(0)).thenComparingInt(o -> o.get(1)));
4
+ int points = 0;
5
+ int intervalStart = -1;
6
+ int intervalEnd = -1;
7
+ for (List<Integer> coordinate : coordinates) {
8
+ if (intervalStart == -1) {
9
+ intervalStart = coordinate.get(0);
10
+ } else {
11
+ if (intervalEnd < coordinate.get(0)) {
12
+ points += intervalEnd - intervalStart + 1;
13
14
+ }
15
16
+ intervalEnd = Math.max(intervalEnd, coordinate.get(1));
17
18
+ return points + intervalEnd - intervalStart + 1;
19
20
+}
0 commit comments