Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int findMaxForm(String[] strs, int m, int n) {
- return helper(strs, m, n);
- }
- public int helper(String[] strs, int m, int n){
- int[][] dp = new int[m+1][n+1];
- for(String str: strs){
- int[] count = count(str);
- for(int i=m;i>=count[0];i--){
- for(int j=n;j>=count[1];j--){
- dp[i][j] = Math.max(1+dp[i-count[0]][j-count[1]], dp[i][j]);
- }
- }
- }
- return dp[m][n];
- }
- public int[] count(String str){
- int[] count = new int[2];
- for(int i=0;i<str.length();i++){
- if(str.charAt(i)=='0'){
- count[0]++;
- } else {
- count[1]++;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement