Skip to content

Commit c6bfd96

Browse files
author
Ihssaneabousshal
committed
Runtime: 116 ms (Top 47.58%) | Memory: 73.6 MB (Top 13.54%)
1 parent ea7f183 commit c6bfd96

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1+
// Runtime: 116 ms (Top 47.58%) | Memory: 73.6 MB (Top 13.54%)
12
// Java Solution
23
class Solution {
34
public int minSessions(int[] tasks, int sessionTime) {
45
int n = tasks.length, MAX = Integer.MAX_VALUE;
56
int[][] dp = new int[1<<n][2];
67
dp[0][0] = 1;
78
dp[0][1] = 0;
8-
9+
910
for(int i = 1; i < (1 << n); i++) {
1011
dp[i][0] = MAX;
1112
dp[i][1] = 0;
12-
13+
1314
for(int t = 0; t < n; t++) {
1415
if(((1<<t) & i) == 0) continue;
15-
16+
1617
int[] prev = dp[(1<<t) ^ i];
1718
if(prev[1] + tasks[t] <= sessionTime) {
1819
dp[i] = min(dp[i], new int[]{prev[0], prev[1] + tasks[t]});
1920
}else{
2021
dp[i] = min(dp[i], new int[]{prev[0] + 1, tasks[t]});
2122
}
22-
}
23+
}
2324
}
24-
25+
2526
return dp[(1<<n) - 1][0];
2627
}
27-
28+
2829
private int[] min(int[] d1, int[] d2) {
2930
if(d1[0] > d2[0]) return d2;
3031
if(d1[0] < d2[0]) return d1;
3132
if(d1[1] > d2[1]) return d2;
32-
33+
3334
return d1;
3435
}
35-
}
36+
}

0 commit comments

Comments
 (0)