[剑指Offer-57-II][简单][双指针] 和为s的连续正数序列
最后更新于
最后更新于
class Solution:
def findContinuousSequence(self, target: int) -> List[List[int]]:
res = []
left, right = 1, 2
while right <= target // 2 + 1:
sum_res = (left + right) / 2 * (right - left + 1)
if sum_res == target:
res.append(list(range(left, right + 1)))
right += 1
elif sum_res < target:
right += 1
else:
left += 1
return res