leet-code/arranging-coins/sol.go

10 lines
188 B
Go
Raw Permalink Normal View History

2021-11-05 15:40:01 +00:00
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)
}