코딩테스트 준비(kotlin)/문자열
[kotlin] 프로그래머스 둘만의 암호
1chanhue1
2024. 5. 30. 10:25
fun solution(s: String, skip: String, index: Int): String {
//"aukks" "wbqd" 5
val s = s.toCharArray()
val skip = skip
val index = index
for (i in 0 until s.size) { //s의 길이만큼
var count = 0
while (count < index) {
s[i] = s[i] + 1
if (s[i] == '{') { // { 는 'z' 다음 문자이다, 다시 'a'로 돌아간다
s[i] = 'a'
}
if (!skip.contains(s[i])) { //skip이란 문자열에 s[i]가 포함되지 않는다면 증가시킴
count++
}
}
}
return s.joinToString("")
}