Skip to content

Commit

Permalink
프로그래머스 스킬테스트 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mong3125 committed Apr 15, 2024
1 parent 7e91c9e commit 9a3eb2f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mong3125/문자열/PS스킬체크테스트2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package 문자열;

import java.util.*;

public class PS스킬체크테스트2 {
class Solution {
public int[] solution(String s) {
int[] answer = new int[s.length()];

HashMap<Character, Integer> alphabet = new HashMap<>();

for (int i = 0; i < s.length(); i++) {
char now = s.charAt(i);
if (alphabet.containsKey(now)) {
answer[i] = i - alphabet.get(now);
} else {
answer[i] = -1;
}

alphabet.put(now, i);
}

return answer;
}
}
}

0 comments on commit 9a3eb2f

Please sign in to comment.