【发布时间】:2021-04-01 12:40:16
【问题描述】:
给定 2 个字符串
例如:
"Hello World" 和
"World Is Awesome"
这不完全是联合。我需要提取一个常见于第一个字符串结尾和第二个字符串开头的子字符串。
在上面的示例中,它将是"World",因为第一个字符串以这个字符列表结尾,第二个字符串以它开头。
最有效的方法是什么?可以是任何语言,但我主要对 python 和 c# 感到好奇。
这是我的解决方案
def union_chars(head, tail):
match = None
for i in range(len(head)):
if tail.startswith(head[-i:]):
match = head[-i:]
return match
【问题讨论】:
-
你能证明自己任何努力解决这个问题吗?
-
是的,我也应该粘贴我的努力。
标签: python c# string substring