Created
June 14, 2022 06:05
-
-
Save AnarCom/63ec40556ae9c25e211e13b4721a039b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.TreeSet | |
enum class LetterStatus { | |
NOT_CORRECT, | |
CONTAINS, | |
CORRECT | |
} | |
// a -> ответ | |
// b -> строка, которая с ним сравнивается | |
fun compareWords(a: String, b: String): List<LetterStatus> { | |
// тут нужно вспомнить про бинарные AVL деревья | |
val treeSet = TreeSet<Char>() | |
// доступ можно ускорить, если придумать как гарантировать, добавление только уникальных букв | |
treeSet.addAll(a.toSet()) | |
val ans = mutableListOf<LetterStatus>() | |
for (i in a.indices){ | |
ans.add( | |
if(a[i] == b[i]){ | |
LetterStatus.CORRECT | |
} else if (treeSet.contains(b[i])){ | |
LetterStatus.CONTAINS | |
} else { | |
LetterStatus.NOT_CORRECT | |
} | |
) | |
} | |
return ans | |
} | |
fun main() { | |
println( | |
compareWords("HELLO", "HLLAO") | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment