Skip to content

Commit 3cd0c26

Browse files
Merge pull request #19 from Priyanshi-Srivastava1611/patch-1
Create Longest Common Prefix
2 parents c14c30e + 9b7efba commit 3cd0c26

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def longestCommonPrefix(self, strs: List[str]) -> str:
3+
if(len(strs)==0):
4+
return ""
5+
else:
6+
strs.sort()
7+
p=strs[0]
8+
c=""
9+
q=strs[len(strs)-1]
10+
if(len(p)==0):
11+
return c
12+
else:
13+
for i in range(min(len(p),len(q))):
14+
if(p[i]==q[i]):
15+
c=c+p[i]
16+
else:
17+
break
18+
return c

0 commit comments

Comments
 (0)