-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.py
More file actions
23 lines (21 loc) · 678 Bytes
/
14.py
File metadata and controls
23 lines (21 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def longestCommonPrefix(self, strs: list[str]) -> str:
if len(strs) == 1:
return strs[0]
else:
max_string = ''
root = strs[0]
i, counter = 1, 1
while i <= len(root):
if root[:i] == strs[counter][:i]:
if counter < len(strs) - 1:
counter += 1
continue
else:
max_string = root[:i]
i += 1
counter = 1
continue
else:
break
return max_string