Created
October 16, 2022 23:05
-
-
Save funyin/9b3ae2347de62b3f3f339ddd9a760a11 to your computer and use it in GitHub Desktop.
Reverse words in string
This file contains hidden or 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
/** | |
* Given an input string, reverse the string word by word | |
* | |
* Input: "reverse words in a string" | |
* Output: "string a in words reverse" | |
*/ | |
fun main(){ | |
val words = "reverse words in a string" | |
print(words.run { | |
split(" ").reversed().joinToString(" ") | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment