-
40. 뉴스 클러스터링코딩 테스트/Level 2 2020. 8. 23. 19:14반응형
https://programmers.co.kr/learn/courses/30/lessons/17677
[1차] 뉴스 클러스터링
2018 KAKAO BLIND RECRUITMENT
2471명 완료복잡하게 보이지만 하나하나 코딩하면 속도제한 걸리는 일도 없고 끝.
파이썬
def find_pair(string): result = [] for index in range(len(string) - 1): temp = string[index: index + 2] if temp.isalpha(): result.append(temp.upper()) return result def solution(str1, str2): set1, set2 = find_pair(str1), find_pair(str2) if not (set1 or set2): return 65536 inter_set = [] for each in set1: if each in set2: set2.remove(each) inter_set.append(each) for each in inter_set: set1.remove(each) return 65536 * len(inter_set) // (len(inter_set) + len(set1) + len(set2))
def solution(str1, str2): set1 = [str1[index: index + 2].upper() for index in range(len(str1) - 1) if str1[index: index + 2].isalpha()] set2 = [str2[index: index + 2].upper() for index in range(len(str2) - 1) if str2[index: index + 2].isalpha()] if not (set1 or set2): return 65536 inter_set = [] for each in set1: if each in set2: set2.remove(each) inter_set.append(each) for each in inter_set: set1.remove(each) return 65536 * len(inter_set) // (len(inter_set) + len(set1) + len(set2))
자바
import java.util.ArrayList; class Solution { ArrayList<String> make_pair_letter(String s) { var result = new ArrayList<String>(); for (var i = 0; i < s.length(); i++) { if (s.length() < i + 2) break; var temp = s.substring(i, i + 2); if (temp.split("[^A-Za-z]", -1).length == 1) { result.add(temp.toLowerCase()); } } return result; } public int solution(String str1, String str2) { var set1 = make_pair_letter(str1); var set2 = make_pair_letter(str2); if (set1.isEmpty() && set2.isEmpty()) return 65536; var inter_set = new ArrayList<String>(); for (var each : set1) { if (set2.contains(each)) { set2.remove(each); inter_set.add(each); } } for (var each : inter_set) { set1.remove(each); } return 65536 * inter_set.size() / (inter_set.size() + set1.size() + set2.size()); } }
반응형