lst.sort()
res = 0
for i in range(len(lst)-1):
if lst - lst > res:
res = lst - lst
return res def fun(s):
n = len(s)
if n < 2: return 0
s.sort()
##result =
return max(map(lambda x, y: x - y,s,s[:-1])) 阴阳神万物主 发表于 2019-12-26 14:18
步长还能大?但是呢,步子太大容易扯到蛋啊。
扯到蛋,后面步上 常规写法
def func294(lst):
lst = list(set(lst))
lst.sort()
maxn = 0
if len(lst) < 2:
return maxn
for i in range(1, len(lst)):
if (t := (lst - lst)) > maxn:
maxn = t
return maxn
楼主,我的程序你只是打了分,没有说耗时啊,我想看看比较比较 本帖最后由 sn8625 于 2019-12-27 09:06 编辑
import random
def fun():
l = []
for i in range(100):
l.append(random.randint(1,999))
print(l)
l.sort(reverse=False)
print(l)
for i in range(len(l)):
if i + 1 < len(l):
yield l - l
else:
yield 0
f = fun()
print(max(list(f)))
def Fun294(L):
Compare = 0
if len(L)<2:
return 0
else:
L.sort()
for i in range(len(L)-1):
if (L - L >Compare):
Compare = L - L
return Compare,(L,L) def f294(s):
if len(s)>1:
s.sort()
re=0
for i in range(len(s)-1):
if s-s>re:
re=s-s
return re
else:
return 0
def f294(L):
if len(L)<2:
return 0
else:
L1=[]
L.sort()
for i in range(len(L)-1):
L1.append(L-L)
return max(L1) def fun294(x):
x = sorted(x)
result = 0
if len(x) < 2:
return result
for i in range(len(x)-1):
if abs(x - x) > result:
result = abs(x - x)
return result
页:
1
[2]