Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: i=0 prefix = size = len(strs) if size ==0: return if size ==1: return strs[0]

class Solution:

def longestCommonPrefix(self, strs: List[str]) -> str:

i=0

prefix = ""

size = len(strs)

if size ==0:

return ""

if size ==1:

return strs[0]

strs.sort()

while i < len(strs)-1 and strs[i][i] == strs[i+1][i]:

prefix +=strs[i][i]

i+=1

return prefix

Leet code is giving me an error:

IndexError: string index out of range while i < len(strs)-1 and strs[i][i] == strs[i+1][i]: Line 11 in longestCommonPrefix (Solution.py) ret = Solution().longestCommonPrefix(param_1) Line 35 in _driver (Solution.py) _driver() Line 46 in (Solution.py)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago