File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int [] fullBloomFlowers (int [][] flowers , int [] people ) {
3
+ List <Integer > starts = new ArrayList <>();
4
+ List <Integer > ends = new ArrayList <>();
5
+
6
+ for (int [] flwr : flowers ){
7
+ starts .add (flwr [0 ]);
8
+ ends .add (flwr [1 ] + 1 );
9
+ }
10
+
11
+ Collections .sort (starts );
12
+ Collections .sort (ends );
13
+ int [] res = new int [people .length ];
14
+
15
+ for (int i = 0 ; i < people .length ; i ++){
16
+ int person = people [i ];
17
+ int startBlooming = BinarySearch (starts , person );
18
+ int stopBlooming = BinarySearch (ends , person );
19
+ res [i ] = startBlooming - stopBlooming ;
20
+ }
21
+ return res ;
22
+ }
23
+
24
+ private int BinarySearch (List <Integer > ls , int target ){
25
+ int l = 0 ;
26
+ int r = ls .size ();
27
+
28
+ while (l < r ){
29
+ int m = l + (r -l )/2 ;
30
+ if (target < ls .get (m ))
31
+ r = m ;
32
+ else
33
+ l = m + 1 ;
34
+ }
35
+ return l ;
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments