File tree 1 file changed +13
-0
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class _474 {
4
4
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
+ */
5
18
public int findMaxForm (String [] strs , int m , int n ) {
6
19
int [][] dp = new int [m + 1 ][n + 1 ];
7
20
for (String str : strs ) {
You can’t perform that action at this time.
0 commit comments