class Solution(object):
_dp = [0]
def numSquares(self, n):
dp = self._dp
while len(dp) <= n:
dp += min(dp[-i*i] for i in range(1, int(len(dp)**0.5+1))) + 1,
return dp[n]
这是 StefanPochmann 给的 python 版本动态规划答案,不知道 while 循环中的“,”是什么语法,如果去掉会直接运行失败。
)