Longest Common Prefix

Problem Given an array of strings, find the longest string that is a prefix of every string in the array. If there is no common prefix, return the empty string.

Input / Output

  • Input: an array of strings strs.
  • Output: the longest common prefix, or "".

Constraints

  • 1 <= n <= 200.
  • Strings may be empty; an empty string in the array forces an empty result. Comparison is case-sensitive.

Example

  • ["flower","flow","flight"] -> "fl"
  • ["dog","racecar","car"] -> ""
added …
LeaderboardSalaryAccount