[LeetCode] 3304. Find the K-th Character in String Game I

Chobby·4일 전

LeetCode

목록 보기
889/907

😎풀이

  1. k번째 단어가 생길 때까지 순회
    1-1. 이전 문장 알파벳의 다음 알파벳으로 구현된 문자열을 기존 문자열 이후에 병합
  2. k번째 알파벳 반환
function kthCharacter(k: number): string {
    let word = "a";
    while (word.length < k) {
        let nextPart = ""
        for(const char of word) {
            const nextCharCode = char.charCodeAt(0) + 1
            nextPart += String.fromCharCode(nextCharCode)
        }
        word += nextPart
    }
    return word[k - 1]
}
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글