Files
PS/leetcode/14.py
Gyubin Han dede0dca01 leetcode
2025-02-19 14:09:55 +09:00

15 lines
447 B
Python

class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
last=strs[0]
for i in range(1,len(strs)):
if len(last)<1:
break
for j in range(min(len(last),len(strs[i]))):
if not last[j]==strs[i][j]:
last=last[0:j]
break
if len(last)>len(strs[i]):
last=last[0:len(strs[i])]
return last