Given an array of n integer, and a moving window(size k), move the window at each iteration from the start of the array, find the sum of the element inside the window at each moving.
classSolution:# @param nums {int[]} a list of integers# @param k {int} size of window# @return {int[]} the sum of element inside the window at each movingdefwinSum(self,nums,k): left, right =0,0 res =[] suum =0while right <len(nums): suum += nums[right]# 刚扩展right,把right加入suumif right >= k -1:# window size满足条件时,结果加入res res.append(suum) suum -= nums[left] left +=1# 写在这里的if中,说明要size达到k时再开始右移left right +=1# right 每次都要右移return res