Coding Test/프로그래머스
[프로그래머스/자바] 배열의 유사도
yurison
2023. 5. 2. 10:31
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;
}
}
Set과 Stream을 이용한 다른 분의 풀이
import java.util.*;
class Solution {
public int solution(String[] s1, String[] s2) {
Set<String> set = new HashSet<>(Arrays.asList(s1));
return (int)Arrays.stream(s2).filter(set::contains).count();
}
}