We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06bb242 commit b0bcc23Copy full SHA for b0bcc23
longest-common-pref.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def longestCommonPrefix(self, strs: List[str]) -> str:
3
+ pref = strs[0]
4
+ for s in strs:
5
+ if pref == "":
6
+ return pref
7
+ for i in range(min(len(s),len(pref))):
8
+ if s[i] != pref[i]:
9
+ pref = pref[:i]
10
+ break
11
+ if len(pref) > len(s):
12
+ pref = pref[:len(s)]
13
0 commit comments