Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public class Solution {
  2. public int findMaxForm(String[] strs, int m, int n) {
  3. return helper(strs, m, n);
  4. }
  5.  
  6. public int helper(String[] strs, int m, int n){
  7.  
  8. int[][] dp = new int[m+1][n+1];
  9. for(String str: strs){
  10.  
  11. int[] count = count(str);
  12.  
  13. for(int i=m;i>=count[0];i--){
  14. for(int j=n;j>=count[1];j--){
  15. dp[i][j] = Math.max(1+dp[i-count[0]][j-count[1]], dp[i][j]);
  16. }
  17. }
  18.  
  19. }
  20. return dp[m][n];
  21. }
  22.  
  23. public int[] count(String str){
  24. int[] count = new int[2];
  25. for(int i=0;i<str.length();i++){
  26. if(str.charAt(i)=='0'){
  27. count[0]++;
  28. } else {
  29. count[1]++;
  30. }
  31. }
  32. return count;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement