Skip to content

Instantly share code, notes, and snippets.

@odhiambo123
Created August 28, 2022 00:29
Show Gist options
  • Save odhiambo123/577e5380f79d98a69228c4f78603f895 to your computer and use it in GitHub Desktop.
Save odhiambo123/577e5380f79d98a69228c4f78603f895 to your computer and use it in GitHub Desktop.
add up to in Kotlin
//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