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
can someone explain why this is wrong?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
