Skip to content

Commit a99f76a

Browse files
committed
Update longest-common-prefix.py
You don't have to loop over the first string since we consider it as our base case. Tested on leetcode
1 parent dfc0894 commit a99f76a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Python/longest-common-prefix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def longestCommonPrefix(self, strs):
1414
return ""
1515

1616
for i in xrange(len(strs[0])):
17-
for string in strs:
17+
for string in strs[1:]:
1818
if i >= len(string) or string[i] != strs[0][i]:
1919
return strs[0][:i]
2020
return strs[0]

0 commit comments

Comments
 (0)