Question: class Solution(object): def longestCommonPrefix(self, strs): result = for i in strs[0]: for j in strs[1]: for k in strs[2]: if i == j and i

class Solution(object):

def longestCommonPrefix(self, strs):

result =""

for i in strs[0]:

for j in strs[1]:

for k in strs[2]:

if i == j and i == k:

result+=i

if len(result) >0:

return result

else:

return result

IndexError: list index out of range for j in strs[1]: Line 5 in longestCommonPrefix (Solution.py) ret = Solution().longestCommonPrefix(param_1) Line 31 in _driver (Solution.py) _driver() Line 41 in (Solution.py)

can someone explain why this is wrong?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!