37. Longest common prefix
Write longestCommonPrefix words, the longest string that is a prefix of every string in words. It is "" when the words share no first character, and also when the list is empty.
Examples
- Input
longestCommonPrefix ["flower", "flow", "flight"]Output"fl" - Input
longestCommonPrefix ["dog", "racecar", "car"]Output""
Submitting also runs 8 hidden tests.
Loading editor…
Type
\to in the editor, or click:Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.
ReadyLn 1, Col 1Lean 4
Draft saved in this browser