[LeetCode]#441. Arranging Coins

n = 5The coins can form the following rows:
¤
¤ ¤
¤ ¤
Because the 3rd row is incomplete, we return 2.
n = 8The coins can form the following rows:
¤
¤ ¤
¤ ¤ ¤
¤ ¤
Because the 4th row is incomplete, we return 3.
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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.