-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_34.java
More file actions
46 lines (41 loc) · 1.07 KB
/
Copy pathDay_34.java
File metadata and controls
46 lines (41 loc) · 1.07 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Assign Cookies
class Solution {
public int findContentChildren(int[] g, int[] s) {
int n = g.length, m = s.length;
int i = 0, j = 0;
Arrays.sort(g);
Arrays.sort(s);
while(i<n && j<m){
if(s[j] >= g[i]) i++;
j++;
}
return i;
}
}
// Maximum Matching of Players With Trainers
class Solution {
public int matchPlayersAndTrainers(int[] players, int[] trainers) {
int n = players.length, m = trainers.length;
Arrays.sort(players);
Arrays.sort(trainers);
int i=0, j=0;
while(i<n && j<m){
if(players[i]<=trainers[j]) i++;
j++;
}
return i;
}
}
// Non-overlapping Intervals
class Solution {
public int eraseOverlapIntervals(int[][] intervals) {
Arrays.sort(intervals,(a,b) -> a[1]-b[1]);
int cnt = 0,ed = intervals[0][1];
for(int i=1;i<intervals.length;i++){
int[] it = intervals[i];
if(ed <= it[0]) ed = it[1];
else cnt++;
}
return cnt;
}
}