forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1601.java
34 lines (30 loc) · 1.03 KB
/
_1601.java
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
package com.fishercoder.solutions;
public class _1601 {
public static class Solution1 {
int max = 0;
public int maximumRequests(int n, int[][] requests) {
helper(requests, 0, new int[n], 0);
return max;
}
private void helper(int[][] requests, int index, int[] count, int num) {
// Traverse all n buildings to see if they are all 0. (means balanced)
if (index == requests.length) {
for (int i : count) {
if (0 != i) {
return;
}
}
max = Math.max(max, num);
return;
}
// Choose this request
count[requests[index][0]]++;
count[requests[index][1]]--;
helper(requests, index + 1, count, num + 1);
count[requests[index][0]]--;
count[requests[index][1]]++;
// Not Choose the request
helper(requests, index + 1, count, num);
}
}
}