C# 알고리즘 코드카타
50. 가장 가까운 같은 글자
잼잼재미
2023. 12. 6. 09:32
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string s) {
List<int> nums = new List<int>();
Char[] chas = s.ToCharArray();
int num;
nums.Add(-1);
for(int i = 1; i < chas.Length; ++i)
{
num = -1;
for(int j = 0; j < i; ++j)
{
if(chas[i] == chas[j])
{
num = i - j;
}
}
nums.Add(num);
}
int[] answer = nums.ToArray();
return answer;
}
}
* Dictionary로 풀이 가능