Created
November 10, 2023 22:17
-
-
Save DjangoLC/a660356414d343ad9b0694f3f811c403 to your computer and use it in GitHub Desktop.
solution
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 basics | |
fun main() { | |
val str ="no todos los carros son azules todos los carros son azules lo sabias sabias" | |
findRepeatedWords(str) | |
} | |
fun findRepeatedWords(str: String) { | |
val split = str.split(" ") | |
val map = mutableMapOf<String, Int>() | |
split.forEach { word -> | |
if (map.containsKey(word)) { | |
val count = map.getValue(word) + 1 | |
map[word] = count | |
} else { | |
map[word] = 1 | |
} | |
} | |
println(map.filter { it.value > 1 }.keys.joinToString(", ")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment