Created
July 2, 2020 13:51
-
-
Save bonoogi/f5f80c37607c47b4bfc475c47dfc3747 to your computer and use it in GitHub Desktop.
swift
This file contains hidden or 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
| class Solution { | |
| func arrangeCoins(_ n: Int) -> Int { | |
| let sq = Int(sqrt(Double(n * 2))) | |
| let diff = sq * (sq + 1) / 2 | |
| if n >= diff { | |
| return sq | |
| } else { | |
| return sq - 1 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
맨 처음에 시도했던 방법. Kotlin