# Leetcode 441. Arranging Coins 給定一個n尋找可以填滿的樓梯階層數。 ## 想法 因為階層如下圖: o oo ooo oooo ..... 所以將數字從0開始累加即可知道總共有幾層為填滿的,這邊應該會有數學解,但先以簡單好懂為主。 程式碼: ``` def arrangeCoins(self, n: int) -> int: ans = 0 if(ans>=n): return ans for i in range(n+1): ans+=i if(ans==n): return i elif(ans>n): return i-1 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up