https://school.programmers.co.kr/learn/courses/30/lessons/120869
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
private static final int NOT_FOUND = 2;
private static final int FOUND = 1;
public int solution(String[] spell, String[] dic) {
int answer = NOT_FOUND;
int[] cnt = new int[26];
for(String str : spell){
char ch = str.charAt(0);
int index = ch - 'a';
cnt[index]++;
}
for(String str : dic){
if(check(str,cnt)){
System.out.println(str);
answer = FOUND;
break;
}
}
return answer;
}
private boolean check(String str,int[] cnt){
int[] temp = new int[26];
int size = str.length();
for(int i = 0 ; i < size ; i++){
char ch = str.charAt(i);
int index = ch - 'a';
temp[index]++;
}
for(int i = 0 ; i < 26 ; i++){
if(temp[i] != cnt[i]){
return false;
}
}
return true;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 영어가 싫어요 (JAVA) (0) | 2023.01.09 |
---|---|
프로그래머스 직사각형 넓이 구하기 (JAVA) (0) | 2023.01.08 |
프로그래머스 공 던지기 (JAVA) (0) | 2023.01.06 |
프로그래머스 과일 장수 (JAVA) (0) | 2023.01.05 |
프로그래머스 문자열 정렬하기 (JAVA) (0) | 2023.01.04 |