[CodeKata] -5

def get_prefix(strs):
  if len(strs) == 0:
    return ""

  prefix = ""
  strs1 = strs[0]
  
  for i in strs[1:]:
    n = 0
    for j in i:
      if j == strs1[n]:
        n += 1
        prefix = strs1[:n]
      else:
        if n == 0:
          return ""
        break

  return prefix
def get_prefix(strs): 
  if len(strs) == 0: 
    return ""

  prefix = "" 
  strs = sorted(strs) 
  
  for i in strs[0]: 
    if strs[-1].startswith(prefix+i): 
      prefix += i 
    else: 
      break 

  return prefix

좋은 웹페이지 즐겨찾기