79. 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 "".
Example 1:
Input : str = ["flowers" , "flow" , "fly", "flight" ]
Output : "fl"
Explanation :
All strings given in array contains common prefix "fl".
Example 2:
Input : str = ["dog" , "cat" , "animal", "monkey" ]
Output : ""
Explanation :
There is no common prefix among the given strings in array.
Now Your Turn!
Pick the correct output for the given inputInput : str = ["lady" , "lazy"]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= str.length <= 200
- 1 <= str[i].length <= 200
- str[i] contains only lowercase English letters.