diff --git a/src/com/hong/www/A621.java b/src/com/hong/www/A621.java new file mode 100644 index 0000000..9d757a1 --- /dev/null +++ b/src/com/hong/www/A621.java @@ -0,0 +1,30 @@ +package com.hong.www; + +import java.util.*; + +public class A621 { + public int leastInterval(char[] tasks, int n) { + int[] temp = new int[n + 1]; + int[] res = new int[26]; + int max = 0; + ArrayList list = new ArrayList<>(); + for (char x : tasks) { + res[x - 'A']++; + } + /* + * for(HashMap.Entry x:task){ + * res[x.getKey()-'A']=x.getValue(); + * } + */ + for (int i=0; i<26; i++) { + if (res[i] > max) { + max = res[i]; + list.clear(); + } else if (res[i] == max) { + list.add((char) (i + 'A')); + } + } + int ans =(n+1)*(max-1)+list.size(); + return Math.max(ans, tasks.length); + } +}