Page tree
Skip to end of metadata
Go to start of metadata
	static class Solution {
        private Map<String, Integer> checked = new TreeMap<>();

        Solution() {
            for (int i = 97; i < 123; i++) {
                char ch = (char)i;
                checked.put(String.valueOf(ch), 0);
            }
        }

        public boolean isBeautiful(String input) {
            final String[] datas = input.split("");
            for (final String data : datas) {
                checked.put(data, checked.getOrDefault(data, 0) + 1);
            }

            Integer max = checked.get("a");

            for (final Map.Entry<String, Integer> entry : checked.entrySet()) {
                if (max == 0) {
                    return false;
                }

                if (entry.getValue() == 0) {
                    return false;
                }

                if (max < entry.getValue()) {
                    return false;
                }
            }

            return true;
        }
    }
  • No labels