python 贪心算法

def get_number(x, r):
l = []
for i in range(len(x)):
if i+1 if x[0]+r>=x[i] and x[0]+r print "----",x[i]
l.append(x[i])
break
def look_forward(i,x,l):
for j in range(i,len(x)):
if x[i]+r print '----',x[j]
l.append(x[j])
return look_forward(j,x,l)
look_forward(i,x,l)
print l

if name == "main":
get_number([1,2,4,5,8,12], 3)

你可能感兴趣的:(python 贪心算法)