Created
August 27, 2022 20:29
-
-
Save odhiambo123/64b49f16375c377229e09f89f1ba6185 to your computer and use it in GitHub Desktop.
Check if a string has repeat characters
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
fun isUnique(str: String): Boolean { | |
val set = mutableSetOf<Char>() | |
for (i in str.indices) { | |
if (set.contains(str[i])) { | |
return false | |
} | |
set.add(str[i].lowercaseChar()) | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment