黎影 发表于 2020-3-23 13:08
def huiwen(list1):
list2 = []
for i in range(len(list1)):
效率有待提升
旅途Z 发表于 2020-3-23 13:08
def is_palindromic(str1, str2):
determine = str1 + str2
if determine == determine[::-1]: ...
效率有待提升
mdphd 发表于 2020-3-23 13:10
先发一个暴力法,再看看能不能优化
效率有待提升
whosyourdaddy 发表于 2020-3-23 21:06
def func357(m):
result = []
n = len(m)
效率有待提升
阴阳神万物主 发表于 2020-3-24 02:58
难度评级:简单
要素分析:枚举 字符串
感受:由于输入数据无规律,双 for 是一种必然(不然就是递归), ...
效率有待提升
小马爱python 发表于 2020-3-25 21:42
萌新小试一下
效率有待提升
已改
def fun357(lst):
if not len(lst):return 0
result=[]
for i in range(len(lst)):
for j in range(len(lst)):
if i!=j and (lst[::-1].startswith(lst) or not lst):
result.append()
return result
fan1993423 发表于 2020-3-27 18:46
已改
解答错误
输入:['a', 'abc', 'aba', '']
输出:[, , , , , , ]
预期结果:[, , , ]
换了种思路
def fun357(lst):
if not len(lst):return 0
result=[]
for i in range(len(lst)):
for j in range(i+1,len(lst)):
a=lst+lst
b=lst+lst
if not len(a)//2 or a[:len(a)//2]==a[-1:int(-len(a)/2)-1:-1]:
result.append()
if not len(b)//2 or b[:len(b)//2]==b[-1:int(-len(b)/2)-1:-1]:
result.append()
return result
本帖最后由 入土 于 2020-3-27 21:18 编辑
顺序不对不知道行不行
def x(word):
list = []
list1 = []
list2 = []
len_word = len(word)
for i in range(len_word):
for d in range(len_word):
if i != d:
new_word = word+word
list.append(new_word)
for each in list:
leng = len(each)
n = 0
while n < leng / 2:
if each != each:
break
else:
n += 1
if n >= leng/2:
print(each)
list1.append(each)
for i in range(len_word):
for d in range(len_word):
if i != d:
new_word = word+word
if new_word in list1:
p =
list2.append(p)
print(list2)
m = ["abcd", "dcba", "lls", "s", "sssll"]
x(m)
fan1993423 发表于 2020-3-27 19:21
换了种思路
输入大数据超时
def huiwen(word):
a=word
b=[]
for i in a:
b.append(i)
c=b.copy()
b.reverse()
if b==c:
return True
def findindex(word):
a=''
b=word
l=len(b)
c=[]
d=[]
for i in range(l):
for j in range(l):
a=''
a=b+b
if huiwen(a) and i!=j:
c.append()
d.append(a)
print(c)
print(d)
word=["abcd", "dcba", "lls", "s", "sssll"]
findindex(word)
zltzlt 发表于 2020-3-27 17:54
效率有待提升
{:10_297:}我会继续努力的
本帖最后由 十月故里 于 2020-4-1 17:42 编辑
def huiwen(i,j):
a=list(''.join())
b=a[:]
a.reverse()
if a==b:
return
def main(list1):
result=[]
result2=[]
for i in list1:
for j in list1:
if i!=j:
res=huiwen(i,j)
if res:
result.append((list1.index(res),list1.index(res)))
result2.append(''.join(res))
return result,result2
if __name__=='__main__':
list1=["abcd","dcba","lls","s","sssll"]
a=main(list1)
print('可以拼出回文串的是',a)
print('拼成的回文串有',a)