We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents adecb0a + 31ada8c commit a7b72beCopy full SHA for a7b72be
java/0474-ones-and-zeroes.java
@@ -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