Home > other >  Leetcode in python3 List can't s [I] operation?
Leetcode in python3 List can't s [I] operation?

Time:10-03

The class Solution:
Def longestCommonPrefix (self, the STRS: List (STR)) : - & gt; STR
Common_str=""
Flag=True
For I in range (len (STRS) [0]) : # this sentence has been an error bounds, running locally, however, the result is correct,
For j in range (len (STRS) :
If STRS [0] [I]!=STRS [j] [I] :
Flag=False
Break
The if flag==False:
Break
The else:
Common_str +=STRS [0] [I]
Return common_str

Then take the first element with min, s=min (STRS), or an error, the parameters of the tip min not empty, can I pass the STRS, obviously is not null,
Later, write like this:
If not STRS: return ""
S=min (STRS) # there is no line, should have nothing to do with front line? But it is not an error,????


Leetcode bug?

CodePudding user response:

The class Solution:
Def longestCommonPrefix (self, the STRS) :
Common_str=""
Flag=True
For I in range (len (STRS [0])) :
For j in range (len (STRS) :
If STRS [0] [I]!=STRS [j] [I] :
Flag=False
Break
The if flag==False:
Break
The else:
Common_str +=STRS [0] [I]
Return common_str


A=Solution ()
STRS=[[' 1 ', '2', '3']]
Print (a. ongestCommonPrefix (STRS))

The incoming STRS is two-dimensional arrays and strings? If this is the type of problem
  • Related