【剑指offer】Q41:和为s的连续正数序列

def sumS(s):
	if s <= 0:
		return

	re = []
	first = 1; last = 2; 
	cursum = first + last
	
	while first <= s >> 1:
		if cursum < s:
			last += 1
			cursum += last
		else:
			if cursum == s:
				re.append((first, last))
			cursum -= first
			first += 1
	return re

你可能感兴趣的:(Algorithm,python,面试题)