Ali Hatami Tajik
2 years ago
1 changed files with 30 additions and 0 deletions
@ -0,0 +1,30 @@ |
|||
"""Common Utilities""" |
|||
|
|||
def max_match(a: str, b: str) -> str: |
|||
"""Maximum matching of intersection of pair of string |
|||
|
|||
This function will return the intersection of two strings from the start. |
|||
|
|||
Example: |
|||
>>> a = "/sys/devices/folan/bahman" |
|||
>>> b = "/sys/devices/fol/bahman" |
|||
>>> max_match(a,b) |
|||
'/sys/dedices/fol' |
|||
|
|||
Args: |
|||
a (str): firsrt string |
|||
b (str): second string |
|||
|
|||
Returns: |
|||
str: intersection of two strings |
|||
""" |
|||
i = 0 |
|||
|
|||
if len(b) < len(a): |
|||
a, b = b, a |
|||
|
|||
for c in a: |
|||
if b[i] == c: |
|||
i += 1 |
|||
else: |
|||
return a[0:i] |
Loading…
Reference in new issue