arranging-coins

This commit is contained in:
Gleb Koval 2021-11-05 15:40:01 +00:00
parent 1d06af2727
commit 98f8727286
No known key found for this signature in database
GPG Key ID: 7C89CDC822F8392B
1 changed files with 9 additions and 0 deletions

9
arranging-coins/sol.go Normal file
View File

@ -0,0 +1,9 @@
package main
import "math"
// Time: O(1) (assuming computer has float64 sqrt instruction)
// Space: O(1)
func arrangeCoins(n int) int {
return int(math.Sqrt(float64(2*n)+0.25) - 0.5)
}