The problem is here:
answer = newList.sort()
sort
does not return the sorted list; rather, it sorts the list in place.
Use:
answer = sorted(newList)
209暴力解法,提交超时:
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
if not nums:
return 0
n = len(nums)
sublength = n + 1
for i in range(n):
sum = 0
for j in range(i,n):
sum += nums[j]
if sum >= target:
sublength = min(sublength, j - i + 1)
break
return 0 if sublength == n+1 else sublength
59 螺旋矩阵,没有什么算法,主要是麻烦,需要边界条件搞清楚。