Skip to content

Commit 7506551

Browse files
refactor 474
1 parent 8c536fb commit 7506551

File tree

1 file changed

+13
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-0
lines changed

src/main/java/com/fishercoder/solutions/_474.java

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
public class _474 {
44
public static class Solution1 {
5+
/**
6+
* credit: https://leetcode.com/problems/ones-and-zeroes/discuss/95811/Java-Iterative-DP-Solution-O(mn)-Space and
7+
* https://leetcode.com/problems/ones-and-zeroes/discuss/95811/Java-Iterative-DP-Solution-O(mn)-Space/100352
8+
* <p>
9+
* The problem can be interpreted as:
10+
* What's the max number of str can we pick from strs with limitation of m "0"s and n "1"s.
11+
*
12+
* Thus we can define dp[i][j] as it stands for max number of str can we pick from strs with limitation of i "0"s and j "1"s.
13+
*
14+
* For each str, assume it has a "0"s and b "1"s, we update the dp array iteratively
15+
* and set dp[i][j] = Math.max(dp[i][j], dp[i - a][j - b] + 1).
16+
* So at the end, dp[m][n] is the answer.
17+
*/
518
public int findMaxForm(String[] strs, int m, int n) {
619
int[][] dp = new int[m + 1][n + 1];
720
for (String str : strs) {

0 commit comments

Comments
 (0)