Created
August 28, 2022 00:29
-
-
Save odhiambo123/577e5380f79d98a69228c4f78603f895 to your computer and use it in GitHub Desktop.
add up to in Kotlin
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
//add up to | |
// Time Complexity: O(1) | |
// Mathematical formula | |
fun addTo(n: Int): Int { | |
val result = n * (n + 1) / 2 | |
print(result) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment