Created
November 13, 2021 13:49
-
-
Save teacons/be9003fac9b2cb479386f71c8dc95652 to your computer and use it in GitHub Desktop.
This file contains 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
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