반응형
문제
https://programmers.co.kr/learn/courses/30/lessons/17677
import java.util.ArrayList;
class Solution {
public int solution(String str1, String str2) {
int answer = 0;
str1 = str1.toUpperCase();
str2 = str2.toUpperCase();
ArrayList<String> list1 = new ArrayList<>();
ArrayList<String> list2 = new ArrayList<>();
String temp;
for(int i = 0 ; i < str1.length()-1; ++i){
temp = str1.substring(i, i+2);
if(
'A' <= temp.charAt(0) && temp.charAt(0) <= 'Z'
&&
'A' <= temp.charAt(1) && temp.charAt(1) <= 'Z'
){
list1.add(temp);
}
}
for(int i = 0 ; i < str2.length()-1; ++i){
temp = str2.substring(i, i+2);
if(
'A' <= temp.charAt(0) && temp.charAt(0) <= 'Z'
&&
'A' <= temp.charAt(1) && temp.charAt(1) <= 'Z'
){
list2.add(temp);
}
}
if(list1.size() + list2.size() == 0)
return 65536;
int total = list1.size() + list2.size();
int common = 0;
for(int i = 0 ; i < list1.size(); ++i){
for(int j = 0 ; j < list2.size(); ++j){
if(list1.get(i).equals(list2.get(j))){
++common;
list2.set(j , "*"); // 한번 카운팅 한거니까 없애기
break;
}
}
}
double result = (double)common / (total-common);
answer = (int) (result * 65536);
return answer;
}
}
반응형
'개발 > 알고리즘' 카테고리의 다른 글
codeup 3733 우박수 길이 (3n+1) (large) (0) | 2021.09.05 |
---|---|
[codeup] 4503 바이러스 (0) | 2021.09.04 |
[프로그래머스] 오픈채팅방 (0) | 2021.08.26 |
[프로그래머스] 문자열 압축 (0) | 2021.08.25 |
[프로그래머스] 순위 검색 (0) | 2021.08.09 |
최근댓글