/ leetcodesolve / Longestcommonprifix.py
swadhinbiswas test commit · 3/25/2024
74b485a
12 lines · 335 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
from typing import List

class Solution:
   def longestCommonPrefix(self, strs: List[str]) -> str:
       if not strs:
           return ""
       for i in range(len(strs[0])):
           for string in strs[1:]:
               if i >= len(string) or string[i] != strs[0][i]:
                   return strs[0][:i]
       return strs[0]