Skip to content

Commit fb6b348

Browse files
author
koss-null
committed
longest_common_prefix
1 parent 2cdbf14 commit fb6b348

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://leetcode.com/problems/longest-common-prefix/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def longestCommonPrefix(self, strs):
3+
min_len = min([len(s) for s in strs])
4+
for i in range(min_len):
5+
if any(filter(lambda s: s[i] != strs[0][i], strs)):
6+
return strs[0][:i]
7+
return strs[0][:min_len]
8+
9+
10+
def main(*strs):
11+
return Solution().longestCommonPrefix(strs)
12+
13+
14+
def get_input(inp):
15+
return inp.split()
16+
17+
18+
def format_output(a):
19+
return a
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"input": "flower flow flight",
3+
"output": "fl"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"input": "dog racecar car",
3+
"output": ""
4+
}

0 commit comments

Comments
 (0)