MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / findMaxForm

Method findMaxForm

java/0474-ones-and-zeroes.java:2–14  ·  view source on GitHub ↗
(String[] strs, int m, int n)

Source from the content-addressed store, hash-verified

1class 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}

Callers

nothing calls this directly

Calls 1

countMethod · 0.45

Tested by

no test coverage detected