https://programmers.co.kr/learn/courses/30/lessons/17677?language=java
import java.util.*;
import java.io.*;
class Solution {
public int solution(String str1, String str2) {
List<String> one_list = new ArrayList<>();
List<String> two_list = new ArrayList<>();
String[] sp1 = str1.split("[^a-zA-Z]");
String[] sp2 = str2.split("[^a-zA-Z]");
Map<String,Integer> map1 = new HashMap<>();
Map<String,Integer> map2 = new HashMap<>();
int cnt=0;
for(String t : sp1){
for(int i=0;i<t.length()-1;i++){
String sub = t.toUpperCase().substring(i,i+2);
map1.put(sub,map1.getOrDefault(sub,0)+1);
cnt++;
}
}
for(String t : sp2){
for(int i=0;i<t.length()-1;i++){
String sub = t.toUpperCase().substring(i,i+2);
map2.put(sub,map2.getOrDefault(sub,0)+1);
cnt++;
}
}
int share =0;
for(Map.Entry<String,Integer> entry : map1.entrySet()){
if(map2.containsKey(entry.getKey())){
share += Math.min(map2.get(entry.getKey()),map1.get(entry.getKey()));
}
}
if(map2.size()==0){
return 65536;
}
int answer = (share)*65536/(cnt-share);
return answer;
}
}