@@ -0,0 +1,1552 @@
+public class Solution %7B%0A  public int scheduleCourse(int%5B%5D%5B%5D courses) %7B%0A    Arrays.sort(courses, (a, b) -%3E a%5B1%5D - b%5B1%5D);%0A    int time = 0;%0A    int count = 0;%0A    for (int i = 0; i %3C courses.length; i++) %7B%0A%0A      // If possible to add the time, then add it.%0A      if (time + courses%5Bi%5D%5B0%5D %3C= courses%5Bi%5D%5B1%5D) %7B%0A        time += courses%5Bi%5D%5B0%5D;%0A        courses%5Bcount++%5D = courses%5Bi%5D;%0A        continue;%0A      %7D%0A%0A      // Not possible to add the current time.%0A      int max = i;%0A%0A      // Iterate through all the past courses to find the max course duration%0A      // out of the possible courses.%0A      for (int j = 0; j %3C count; j++)%0A        if (courses%5Bj%5D%5B0%5D %3E courses%5Bmax%5D%5B0%5D) max = j;%0A%0A      // If the max value has changed, then update the time to be the difference of the old max and the new max.%0A      // In other words, remove the biggest course from the schedule and update the time.%0A      if (courses%5Bmax%5D%5B0%5D != courses%5Bi%5D%5B0%5D) %7B%0A        time += courses%5Bi%5D%5B0%5D - courses%5Bmax%5D%5B0%5D;%0A        courses%5Bmax%5D = courses%5Bi%5D;%0A      %7D%0A    %7D%0A%0A    return count;%0A  %7D%0A%0A  // Recursive implementation%0A  public int scheduleCourse(int%5B%5D%5B%5D courses) %7B%0A    Arrays.sort(courses, (a, b) -%3E a%5B1%5D - b%5B1%5D);%0A    return helper(courses, 0, 0, 0);%0A  %7D%0A%0A  public int helper(int%5B%5D%5B%5D courses, int cur, int i, int day) %7B%0A    if (i %3E= courses.length) return cur;%0A%0A    int without = helper(courses, cur, i + 1, day);%0A    int with = 0;%0A    if (courses%5Bi%5D%5B0%5D + day %3C= courses%5Bi%5D%5B1%5D) %0A      with = helper(courses, cur + 1, i + 1, day + courses%5Bi%5D%5B0%5D);%0A%0A    return Math.max(with, without);%0A  %7D%0A%7D%0A

Rename course schedule iii