반응형
단어변환
-
프로그래머스 - 단어 변환알고리즘 문제 풀이 2021. 1. 2. 00:14
/* * 2021-01-01 * https://programmers.co.kr/learn/courses/30/lessons/43163 */ fun wordConversion(begin: String, target: String, words: Array): Int { // words 에 target 이 없는 경우 0 반환 if (!words.any { it == target }) { return 0 } // begin 을 포함한 allWords 생성 val allWords = words.plus(begin) // 각 단어별 노드 생성 val nodeMap = allWords.associate { it to WordNode(it) } nodeMap.forEach { (word, node) -> // 한글자만..