티스토리 뷰
728x90
SMALL




function solution(str1, str2) {
str1=str1.toUpperCase();
str2=str2.toUpperCase();
const arr1=newArr(str1);
const arr2=newArr(str2);
arr1.sort();
arr2.sort();
let union=0; //교집합
let inter=0; //합집합
for (var i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) >= 0) {
union++;
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
inter++
}
for (var i = 0; i < arr1.length; i++) {
inter++
}
if (inter === 0) return 65536
if (union === 0) return 0
return Math.floor((union / inter) * 65536)
}
function newArr(text){
let arr=[];
for(let i=0;i<text.length-1;i++){
let temp=text.slice(i,i+2);
if(temp.match(/[A-Z]{2}/)) arr.push(temp);
}
return arr;
}
뭔가 잘 안풀렸다... 정규식빼고는 별 다를게 없다
728x90
LIST
'코딩테스트' 카테고리의 다른 글
프로그래머스 1단계 답지2 (0) | 2020.12.27 |
---|---|
프로그래머스 1단계 답지1 (0) | 2020.12.25 |
코딩테스트 연습 > 2017 팁스타운 > 예상 대진표 (0) | 2020.08.27 |
코딩테스트 연습 > Summer/Winter Coding(2019) > 멀쩡한 사각형 (0) | 2020.08.25 |
코딩테스트 연습 > 2017 팁스타운 > 짝지어 제거하기 (0) | 2020.08.25 |
공지사항