Q:

Write a function to find the longest common prefix string amongst an array of strings

0

Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

Input Example:

    Example 1:
    Let the set of strings to be {"flower", "fly", "flow"}
    The longest common prefix is "fl"

    Example 2:
    Let the set of strings to be {"dog", "donkey", "door", "cat"}
    The longest common prefix is "", i.e., empty string. 
    Since there is no common prefix at all. 

Longest common prefix

Longest common prefix simply means the longest prefix (prefix is a substring also, but not vice-versa) all the member strings consist of.

All Answers

total answers (0)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now