Skip to content

Instantly share code, notes, and snippets.

@odhiambo123
Created August 27, 2022 20:29
Show Gist options
  • Save odhiambo123/64b49f16375c377229e09f89f1ba6185 to your computer and use it in GitHub Desktop.
Save odhiambo123/64b49f16375c377229e09f89f1ba6185 to your computer and use it in GitHub Desktop.
Check if a string has repeat 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