[LeetCode]#441. Arranging Coins
1 min readMar 21, 2020
Environment: Python 3.7
Key technique: For, if
Example 1:
n = 5The coins can form the following rows:
¤
¤ ¤
¤ ¤Because the 3rd row is incomplete, we return 2.
Example 2:
n = 8The coins can form the following rows:
¤
¤ ¤
¤ ¤ ¤
¤ ¤Because the 4th row is incomplete, we return 3.
Solution:
class Solution:
def arrangeCoins(self, n: int) -> int:
half=n/2
if n==1:
return n
else:
for i in range(1,(int(half)+2)):
if n<i:
return i-1
break
elif n==i:
return i
else:
n=n-i
Submitted result:
Lesson learn:
I don’t consider 1, and remainder is zero case. I spend more time to fix it.