From a95031128db8dd976f3555798a6b543bfcdb02f0 Mon Sep 17 00:00:00 2001 From: sangge-rockpi <2251250136@qq.com> Date: Sat, 20 Jan 2024 03:39:05 +0800 Subject: [PATCH] add leetcode 14 --- leetcode/14.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 leetcode/14.py diff --git a/leetcode/14.py b/leetcode/14.py new file mode 100644 index 0000000..7c77d8f --- /dev/null +++ b/leetcode/14.py @@ -0,0 +1,21 @@ +# find the longest common prefix +# 1 <= strs.length <= 200 +# 0 <=strs[i].length <= 200 +# only lowercase +class Solution: + def longestCommonPrefix(self,strs: list[str]) -> str: + returnString = "" + index = 0 + while i < len(str[0]): + try: + for string in strs: + if string[i] == strs[0][i]: + i += 1 + returnString += string[i] + else: + break + except: + break + + return returnString +