Create A621.java

This commit is contained in:
Mrhongxing committed 2026-10-20 17:01:41 +08:00
1 parent b0d0679a64
commit 60ca41cf34
1 file changed
+30
+30
View File
@@ -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<Character> list = new ArrayList<>();
for (char x : tasks) {
res[x - 'A']++;
}
/*
* for(HashMap.Entry<Character,Integer> 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);
}
}