using System;
public class Solution {
public int[] solution(string[] keymap, string[] targets) {
int[] answer = new int[keymap.Length];
for(int i = 0; i < keymap.Length; ++i)
{
answer[i] = 0;
}
int count = -2;
for(int i = 0; i < targets.Length; ++i)
{
for(int j = 0; j < targets[i].Length; ++j)
{
for(int z = 0; z < keymap.Length; ++z)
{
if(count == -2)
{
int c = keymap[z].IndexOf(targets[i][j]);
if(c >= 0)
{
count = c + 1;
}
else continue;
}
else
{
int c = keymap[z].IndexOf(targets[i][j]);
if (c >= 0)
{
if (count > c + 1) count = c + 1;
}
else continue;
}
}
if(count == -2)
{
answer[i] = -1;
break;
}
else
{
answer[i] += count;
count = -2;
}
}
}
return answer;
}
}
샘플 테스트만 통과, 코트 수정 필요
'C# 알고리즘 코드카타' 카테고리의 다른 글
68. 햄버거 만들기 (0) | 2024.01.16 |
---|---|
67. 둘만의 암호 (0) | 2024.01.15 |
65. 문자열 나누기 (1) | 2024.01.09 |
64. 체육복 (2) | 2024.01.05 |
63. 숫자 짝꿍 (2) | 2024.01.04 |