👨‍💻 dev DiPerChance

development

fukurou

the supreme coder
ADMIN
Python:
def find_contained_substring(target: str, substrings: list[str]) -> str:
    """
    Find the first substring contained in the target string.

    :param target: The string to search within.
    :param substrings: A list of substrings to search for.
    :return: The first substring found in the target, or an empty string if none are found.
    """
    for substring in substrings:
        if substring in target:
            return substring
    return ""

# Example usage
target_string = "example"
strings_to_check = ["zz", "am", "ex"]

result = find_contained_substring(target_string, strings_to_check)
if result:
    print(f"Found: {result}")  # Output: Found: am
else:
    print("No match found.")

complexity is O(N len(target)Ă—M count substrings)
 
Top