This commit is contained in:
jxxghp
2023-10-26 16:45:09 +08:00
parent a85d55f3a8
commit 935ad73d32
2 changed files with 20 additions and 1 deletions

View File

@ -656,3 +656,18 @@ class StringUtils:
return True
except ValueError:
return False
@staticmethod
def find_common_prefix(str1: str, str2: str) -> str:
if not str1 or not str2:
return ''
common_prefix = []
min_len = min(len(str1), len(str2))
for i in range(min_len):
if str1[i] == str2[i]:
common_prefix.append(str1[i])
else:
break
return ''.join(common_prefix)