Untitled
unknown
java
3 years ago
1.1 kB
9
Indexable
LinkedList<Job> jobs = new LinkedList<>();
for(int i = 1; i <= n; i++) {
Job job = new Job(starttimes[i], starttimes[i] + durations[i]);
jobs.add(job);
System.out.println(jobs.get(i).starttime);
}
Collections.sort(jobs);
int count = 1;
int nbEmployees = 0;
for(int i = 2; i < jobs.size(); i++) {
count = 1;
for(int j = 1; j < jobs.size(); j++) {
if(jobs.get(j).duration > jobs.get(i).starttime) {
count++;
}
}
if(count > nbEmployees) {
nbEmployees = count;
}
}
return nbEmployees;
}
static class Job implements Comparable<Job> {
public int starttime;
public int duration;
public Job(int starttime, int duration) {
this.starttime = starttime;
this.duration = duration;
}
@Override
public int compareTo(Job o) {
return this.starttime - o.starttime;
}
}Editor is loading...