AcWing 3168. 次数差
原题链接
简单
作者:
zshprint
,
2021-04-13 20:25:10
,
所有人可见
,
阅读 406
import java.util.*;
public class Main{
static HashMap<Character,Integer> map = new HashMap<Character,Integer>();
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String x = sc.nextLine();
for(int i = 0; i<x.length(); i++){
map.put(x.charAt(i),map.getOrDefault(x.charAt(i),0)+1);
}
int max = Integer.MIN_VALUE,min = Integer.MAX_VALUE;
for(Map.Entry<Character,Integer> set:map.entrySet()){
int value = set.getValue();
if(max < value) max = value;
if(min > value) min = value;
}
System.out.println(max - min);
}
}
这代码太长了,看的难受,算法中应该简洁点啊
华子哥upup
赶紧滚
强啊,华哥