Skip to content

Instantly share code, notes, and snippets.

@teacons
Created November 13, 2021 13:49
Show Gist options
  • Save teacons/be9003fac9b2cb479386f71c8dc95652 to your computer and use it in GitHub Desktop.
Save teacons/be9003fac9b2cb479386f71c8dc95652 to your computer and use it in GitHub Desktop.
package ru.fbear.strings
class Strings {
fun shuflled(source: String, shuffled: String): Boolean {
val sourceCharMap: MutableMap<Char, Int> = mutableMapOf()
for (char in source) {
if (!sourceCharMap.containsKey(char)) sourceCharMap[char] = 1
else sourceCharMap[char] = sourceCharMap[char]!! + 1
}
val shuffledCharMap: MutableMap<Char, Int> = mutableMapOf()
for (char in shuffled) {
if (!shuffledCharMap.containsKey(char)) shuffledCharMap[char] = 1
else shuffledCharMap[char] = shuffledCharMap[char]!! + 1
}
return sourceCharMap == shuffledCharMap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment