Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int findMaxForm(String[] strs, int m, int n) {
- int len = strs.length;
- List<int[]> freqs = new LinkedList<int[]>();
- for(int i=0;i<len;i++){
- int[] freq = new int[2];
- String str = strs[i];
- int slen = str.length();
- for(int j=0;j<slen;j++){
- freq[str.charAt(j)-'0']++;
- }
- freqs.add(freq);
- }
- return helper(freqs,0,m,n);
- }
- public int helper(List<int[]> cand, int pos,int m,int n ){
- int len = cand.size();
- int dep = Integer.MIN_VALUE;
- for(int i = pos;i<len;i++){
- int[] temp = cand.get(i);
- m-= temp[0];
- n-= temp[1];
- if(m>=0&&n>=0){
- dep =Math.max(dep,helper(cand,i+1,m,n)+1);
- }
- m+= temp[0];
- n+= temp[1];
- }
- return dep==Integer.MIN_VALUE?0 : dep;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement