长度最小子数组
class Solution:
def small(self,nums,target)->int:
left = 0
right = 0
sum = 0
result = float('inf')
while right < len(nums):
sum += nums[right]
while sum >= target :
sum -= nums[left]
result = min(result,right-left+1)
left += 1
right +=1
if result != float('inf'):
return result
else:
return 0
螺旋矩阵
class Solution(object):
def generateMatrix(self, n):
list = [[0]*n for _ in range(n)]
startx = 0
starty = 0
count = 1
for offset in range(1,n//2+1):
for j in range(starty,n-offset):
list[startx][j] = count
count += 1
for i in range(startx,n-offset):
list[i][n-offset]= count
count += 1
for j in range(n-offset,starty,-1):
list[n-offset][j] = count
count += 1
for i in range(n-offset,startx,-1):
list[i][starty] = count
count +=1
startx += 1
starty += 1
if n%2!=0:
list[startx][starty] = count
return list