```
def numSquares(self, n):
"""
:type n: int
:rtype: int
"""
if n < 4:
return n
if n == 4:
return 1
res = dict()
res[0] = 0
res[1] = 1
res[2] = 2
res[3] = 3
res[4] = 1
for i in range(5,n+1):
res[i] = sys.maxint
j = 1
while j*j <= i:
if j*j == i:
res[i] = 1
else:
res[i] = min(res[i], 1+res[i-j*j])
j += 1
return res[n]
```

I think my python solution is correct. And some test cases can be passed through "Custom TestCase", but not through submission. I am really confused....