728x90
SMALL

using System;

public class Solution {
    public int solution(string[] s1, string[] s2) {
        int answer = 0;
        
            for(int i=0;i<s1.Length;i++)
            {
                for(int j=0; j<s2.Length;j++)
                {
                    if(s1[i].Equals(s2[j]))  //if(s1[i] == s2[j])로도 해도 된다.
                    {
                       answer++;
                    }    
                }
            }       
        return answer;
    }
}

 

////

using System;
using System.Linq;

public class Solution {
    public int solution(string[] s1, string[] s2) {
        int answer = s1.Count(x => s2.Contains(x));
        return answer;
    }
}

파이썬

 

////

 

def solution(s1, s2):
    count = 0

    for val in s1:
        if val in s2:
            count += 1
    return count

 

//////

 

def solution(s1, s2):
    return len(set(s1)&set(s2));

 

 

자바

 

 

class Solution {
    public int solution(String[] s1, String[] s2) {
        int answer = 0;
        for(int i=0; i<s1.length; i++)
        {
            for(int j=0; j<s2.length; j++)
            {
                if(s1[i].equals(s2[j])) answer ++;
            }
        }
        return answer;
    }
}

 

 

import java.util.HashSet;
import java.util.List;
class Solution {

    public int solution(String[] s1, String[] s2) {
        int answer = 0;
        HashSet<String> set = new HashSet<>(List.of(s1));
        
        for (String s : s2) 
        {
            if(set.contains(s))
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

728x90

설정

트랙백

댓글