You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dict에 글자의 지난 index를 저장해두고 해당 글자가 다시 나오면 최신 index에서 지난 index를 빼서 index의 차이를 구하자.
💬 풀이
func solution(_ s:String)->[Int]{varwordIndexDict:[String:Int]=[:]varresult:[Int]=[]
for (index, i) in s.enumerated(){letword=String(i)
if wordIndexDict[word]!=nil{
result.append(index - wordIndexDict[word]!)}else{
result.append(-1)}wordIndexDict[word]= index
}return result
}
The text was updated successfully, but these errors were encountered:
💬 문제
[코딩테스트 연습 - 가장 가까운 같은 글자](https://school.programmers.co.kr/learn/courses/30/lessons/142086)
💬 Idea
💬 풀이
The text was updated successfully, but these errors were encountered: