Skip to content

Longest Common Prefix

EasyArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.

Given a list of strings strs, return the longest prefix shared by every string. If there is no common prefix, return the empty string "".

strs = ["flower", "flow", "flight"]   →  "fl"
strs = ["dog", "racecar", "car"]     →  ""
strs = ["alone"]                      →  "alone"

Constraints

  • 1 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • strs[i] contains only lowercase English letters.