代码随想录算法训练营第二天|209.长度最小的子数组
class Solution: def minSubArrayLen(self, target: int, nums: List[int]) -> int: min_len=float('inf') i=0 j=0 sums=0 l=len(nums) while j<l: sums+=nums[j] while sums>=target: min_len=min(j-i+1,min_len) sums-=nums[i] i+=1 j+=1 return min_len if min_len!=float('inf') else 0
如果将第二个while换成if将会出现什么情况?
class Solution: def generateMatrix(self, n: int) -> List[List[int]]: nums=[[0]*n for _ in range(n)] startx,starty=0,0 loop,mid=n//2,n//2 count=1 for offset in range(1,loop+1): for i in range(starty,n-offset): nums[startx][i]=count count+=1 for i in range(startx,n-offset): nums[i][n-offset]=count count+=1 for i in range(n-offset,starty,-1): nums[n-offset][i]=count count+=1 for i in range(n-offset,startx,-1): nums[i][starty]=count count+=1 startx+=1 starty+=1 if n%2 !=0: nums[mid][mid]=count return nums