码迷,mamicode.com
首页 > 其他好文 > 详细

Build a pile of Cubes

时间:2019-06-11 01:13:46      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:lse   ret   ==   bsp   code   ota   pil   for   +=   

version_1:


def find_nb(m):
# your code
ii = 1
total = 0
while total < m:
total = sum(each**3 for each in range(ii))
ii += 1
if total == m:
result = ii-2
else:
result = -1
return result

 

version_2:

 

def find_nb(m):
# your code
i = 1
while m>0:
m = m - i**3
i += 1
return -1 if m<0 else i-1

Build a pile of Cubes

标签:lse   ret   ==   bsp   code   ota   pil   for   +=   

原文地址:https://www.cnblogs.com/cepaAllium/p/11001227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!