https://school.programmers.co.kr/learn/courses/30/lessons/142086?language=java
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 및 입출력
코드
class Solution
{
public int[] solution(String s)
{
int[] answer = new int[s.length()];
for(int i=0; i<s.length(); i++)
{
char c = s.charAt(i);
if(i==0)
{
answer[i] = -1;
}
else
{
for(int j=i-1; j>=0; j--)
{
if(c==s.charAt(j))
{
answer[i] = Math.abs(i-j);
break;
}
answer[i] = -1;
}
}
}
return answer;
}
}
'[ 다먹살 ] > - Coding' 카테고리의 다른 글
[프로그래머스] 레벨1 크기가 작은 부분 문자열 (0) | 2023.02.06 |
---|---|
[프로그래머스] 레벨1 개인정보 수집 유효기간 (0) | 2023.02.03 |
[프로그래머스] 레벨 0 푸드 파이트 (0) | 2022.11.08 |
[프로그래머스] 레벨0 콜라문제 (0) | 2022.10.28 |
[프로그래머스] 레벨0 연속된 수의 합 (0) | 2022.10.25 |
댓글