Algorithm/프로그래머스 22

가장 가까운 같은 글자 C언어 Lv.1

#include #include #include int* solution(const char* s) { int len = strlen(s); int* answer = (int*)malloc(sizeof(int)*(len + 1)); //처음나온 애 answer[0] = -1; //두번째 알파벳부터 for(int i = 1; i = 0; j--) { //같은 알파벳이 있으면 if(s[j] == s[i]){ //몇칸앞에 있는지 저장 answer[i] = i - j; break; } //같은 알파벳이 없으면 -1 else answer[i] = -1; } } //맨 마지막 NULL로 초기화 answer[len] ..