https://school.programmers.co.kr/learn/courses/30/lessons/142086
class Solution {
public int[] solution(String s) {
int[] answer = new int[s.length()];
char[] arr = s.toCharArray();
for(int i=0; i<s.length(); i++){
String s2 =s.substring(0,i+1);
if(s2.indexOf(arr[i])==s2.lastIndexOf(arr[i])){
answer[i]=-1;
}
else{
int a= s2.lastIndexOf(arr[i]);
String s3=s.substring(0,i);
int b = s3.lastIndexOf(arr[i]);
answer[i]=a-b;
}
}
return answer;
}
}