Created
January 8, 2020 12:10
-
-
Save toantran-ea/761fe2f4267caaa1493ebcff2152a308 to your computer and use it in GitHub Desktop.
Tail Recursion function to solve Reachable Number problem
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
tailrec fun removeZeroes(x: Int): Int = | |
if (x % 10 == 0) removeZeroes(x / 10) else x | |
fun f(x: Int) = removeZeroes(x + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment