[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] 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;
    }
}
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ