Skip to content

Instantly share code, notes, and snippets.

@mapleqin
Created June 19, 2017 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapleqin/c7d888f35b44a9a5cac989fbd545b4f3 to your computer and use it in GitHub Desktop.
Save mapleqin/c7d888f35b44a9a5cac989fbd545b4f3 to your computer and use it in GitHub Desktop.
public static int[] number_of_tasks_running(int[] start, int[] end, int n, int[] query, int m) {
int[] out_task = query;
int count;
int min = 0;
int max = 0;
for (int i = 0; i < n; i++) {
if (min >= start[i]) {
min = start[i];
}
if (max <= end[i]) {
max = end[i];
}
}
for (int i = 0; i < m; i++) {
if(query[i]<min || query[i]>=max){
query[i] = 0;
continue;
}
count = 0;
for (int j = 0; j < n; j++) {
if (query[i] >= start[j] && query[i] < end[j]) count++;
}
out_task[i] = count;
}
return out_task;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment