Skip to content

Commit 31ada8c

Browse files
authored
Create 0474-ones-and-zeroes.java
1 parent f39968f commit 31ada8c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

java/0474-ones-and-zeroes.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int findMaxForm(String[] strs, int m, int n) {
3+
int[][] dp = new int[m + 1][n + 1];
4+
for (String str : strs) {
5+
int zeros = (int) str.chars().filter(ch -> ch == '0').count();
6+
int ones = (int) str.chars().filter(ch -> ch == '1').count();
7+
for (int i = m; i >= zeros; i--) {
8+
for (int j = n; j >= ones; j--) {
9+
dp[i][j] = Math.max(dp[i][j], dp[i - zeros][j - ones] + 1);
10+
}
11+
}
12+
}
13+
return dp[m][n];
14+
}
15+
}

0 commit comments

Comments
 (0)