[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 [1์ฐจ] ๋ด์ค ํด๋ฌ์คํฐ๋ง
1. ๋ฌธ์ : Link
๋ฌธ์์ด์ด ์ฃผ์ด์ก์ ๋ ๋ค์ค์งํฉ์ ๊ต์งํฉ๊ณผ ํฉ์งํฉ์ ๊ตฌํ๋ ๋ฌธ์
2. ํ์ด
๋ฌธ์์ด์ ์ ์ ํด์ฃผ๊ณ ๊ต์งํฉ ํฉ์งํฉ์ ๊ตฌํ๋ฉด ๋๋ค.
3. ์ฝ๋
def solution(str1, str2):
str1 = str1.lower()
str2 = str2.lower()
one = []
two = []
for i in range(len(str1)-1):
if str1[i].isalpha() and str1[i+1].isalpha():
one.append(str1[i] + str1[i+1])
for j in range(len(str2)-1):
if str2[j].isalpha() and str2[j+1].isalpha():
two.append(str2[j] + str2[j+1])
temp = two.copy()
h = two.copy()
for i in one:
if i in temp:
temp.remove(i)
else:
h.append(i)
temp = two.copy()
g = []
for i in one:
if i in temp:
g.append(i)
temp.remove(i)
if len(h) == 0:
usa = 1
else:
usa = len(g) / len(h)
return int(usa * 65536)
import java.util.*;
class Solution {
public int solution(String str1, String str2) {
int answer = 0;
int hap = 0;
int gyo = 0;
List<String> arr1 = new ArrayList<String>();
List<String> arr2 = new ArrayList<String>();
for(int i=0; i<str1.length()-1; i++){
if(Character.isLetter(str1.charAt(i)) && Character.isLetter(str1.charAt(i+1))){
String temp = str1.substring(i,i+2).toUpperCase();
arr1.add(temp);
}
}
for(int i=0; i<str2.length()-1; i++){
if(Character.isLetter(str2.charAt(i)) && Character.isLetter(str2.charAt(i+1))){
String temp = str2.substring(i,i+2).toUpperCase();
arr2.add(temp);
}
}
if(arr1.size() == 0 && arr2.size() ==0) return 65536;
hap = arr1.size() + arr2.size();
for(int i=0; i<arr1.size(); i++){
int j=0;
while(true){
if(arr1.get(i).equals(arr2.get(j))){
gyo++;
arr2.remove(j);
j--;
break;
}
j++;
if(j == arr2.size()) break;
}
}
hap -= gyo;
float tep;
tep = (float)gyo/hap*65536;
answer = (int)tep;
return answer;
}
}
์ต๊ทผ๋๊ธ