Skip to content

Commit 3a38054

Browse files
authored
Merge pull request neetcode-gh#1213 from UdayGarg/14-longest-common-prefix
Create: 14-Longest-Common-Prefix.py
2 parents 3a3194d + b866064 commit 3a38054

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

python/14-Longest-Common-Prefix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def longestCommonPrefix(self, strs: List[str]) -> str:
3+
res = ""
4+
for i in range(len(strs[0])):
5+
for s in strs:
6+
if i == len(s) or s[i] != strs[0][i]:
7+
return res
8+
res += strs[0][i]
9+
return res

0 commit comments

Comments
 (0)