@zltzlt
多改了一个-1,这次应该对了。
好了,135 ms 本帖最后由 kinkon 于 2020-4-16 05:58 编辑
这时间差得有点多啊,看来优化空间很大 kinkon 发表于 2020-4-15 13:40
没看懂 def f376(word1, word2):
overlap = 0
if len(word2) > len(word1):
t = word1
word1 = word2
word2 = t
for i in range(0, len(word1)):
for j in range(0, len(word2)):
if word1 == word2:
a, count = 0, 1
while 1:
a += 1
if (i+a > len(word1)-1) or (j+a > len(word2)-1):
break
if (word1 == word2):
count += 1
else:
break
overlap = count if count > overlap else overlap
return (len(word1) - overlap) + (len(word2) - overlap) def f376(word1, word2):
overlap = 0
for i in range(0, len(word1)):
for j in range(0, len(word2)):
if word1 == word2:
a, count = 0, 1
while 1:
a += 1
if (i+a > len(word1)-1) or (j+a > len(word2)-1):
break
if (word1 == word2):
count += 1
else:
break
overlap = count if count > overlap else overlap
return (len(word1) - overlap) + (len(word2) - overlap) def daily376(world1="sssas", world2="sssts"):
a = []
b = []
i = 0
k = len(world1)
t = len(world2)
j = 0
while i < k or j < t:
if i < k:
a.append(world1)
if world2 in a:
a.remove(world2)
j += 1
i += 1
if i == k and j != t:
if world2 not in a:
b.append(world2)
j += 1
print(len(a) + len(b))
daily376()
时间,空间复杂度都为log(n),{:5_104:} def daily376(world1="sssas", world2="sssts"):
a = []
b = []
i = 0
k = len(world1)
t = len(world2)
j = 0
while i < k or j < t:
if i < k:
a.append(world1)
if world2 in a:
a.remove(world2)
j += 1
i += 1
if i >= k and j != t:
if world2 not in a:
b.append(world2)
j += 1
print(len(a) + len(b))
daily376()
遗漏一个条件world 1< world 2 def fun376(word1,word2):
count = 0
pointer = 0
while pointer <= len(word2)-1:
if word1 == '':
count += 1
pointer += 1
continue
elif word1 != word2:
word1 = word1
count += 1
elif word1 == word2:
word1 = word1
pointer += 1
return count 不会,来看答案
页:
1
[2]