47. Longest Common Prefix
Easy
Given an array of words, return the longest prefix that appears at the beginning of all of them. If there are no words or no shared prefix, return an empty string.
Example 1
Input: palavras = ["janela", "jantar", "jangada"]
Output: "jan"
Example 2
Input: palavras = ["sol", "lua"]
Output: ""
Explanation: The words start with different letters.
Constraints
- 0 <= palavras.length <= 200
- Cada palavra contém apenas letras minúsculas de a a z.
- 0 <= palavras[i].length <= 200
Strings
Saved in this browser
Caso 1
palavras =
["janela","jantar","jangada"]
Expected =
"jan"
Caso 2
palavras =
["sol","lua"]
Expected =
""
Run checks these 2 cases. Submit runs all 6, including hidden ones.