package leetcode;

/**
 * https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/
 */
public class Problem1160 {
    public int countCharacters(String[] words, String chars) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1160 prob = new Problem1160();
        System.out.println(prob.countCharacters(new String[]{"cat","bt","hat","tree"}, "atach")); // 6
        System.out.println(prob.countCharacters(new String[]{"hello","world","leetcode"}, "welldonehoneyr")); // 10
    }
}

@@ -200,94 +200,204 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D 
+int answer = 0;%0A        for (String word : words) %7B%0A            if (word.length() %3E chars.length()) %7B%0A                continue;%0A            %7D%0A            int%5B%5D counts = counts(ch
 ar
-g
 s)
- %7B%0A
+;%0A    
         
 Prob
@@ -396,264 +396,591 @@
     
-Problem1160 prob = new Problem1160();%0A        System.out.println(prob.countCharacters(new String%5B%5D%7B%22cat%22,%22bt%22,%22hat%22,%22tree%22%7D, %22atach%22)); // 6%0A        System.out.println(prob.countCharacters(new String%5B%5D%7B%22hello%22,%22world%22,%22leetcode%22%7D, %22welldonehoneyr%22)); // 10
+boolean found = true;%0A            for (char c : word.toCharArray()) %7B%0A                if (counts%5Bc - 'a'%5D == 0) %7B%0A                    found = false;%0A                    break;%0A                %7D else %7B%0A                    counts%5Bc - 'a'%5D--;%0A                %7D%0A            %7D%0A            if (found) %7B%0A                answer += word.length();%0A            %7D%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static int%5B%5D counts(String chars) %7B%0A        int%5B%5D counts = new int%5B26%5D;%0A        for (char c : chars.toCharArray()) %7B%0A           counts%5Bc - 'a'%5D++;%0A        %7D%0A        return counts;
 %0A   

Solve problem 1160