diff --git a/README.md b/README.md index 400b1e9322..31febf2dd8 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★ | # | Title | Solutions | Video | Difficulty | Tag |-----|----------------|---------------|--------|-------------|------------- +|1601|[Maximum Number of Achievable Transfer Requests](https://leetcode.com/problems/maximum-number-of-achievable-transfer-requests/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1601.java) ||Hard|Backtracking| |1598|[Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1598.java) ||Easy|Stack| |1592|[Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1592.java) ||Easy|String| |1588|[Sum of All Odd Length Subarrays](https://leetcode.com/problems/sum-of-all-odd-length-subarrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1588.java) ||Easy|Array| diff --git a/src/main/java/com/fishercoder/solutions/_1601.java b/src/main/java/com/fishercoder/solutions/_1601.java new file mode 100644 index 0000000000..2c27f6e886 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/_1601.java @@ -0,0 +1,29 @@ +class Solution { + 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); + } +} \ No newline at end of file