返回列表中最长的连续字符串

题目描述:

  

# You are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.
#
# Example:
# longest_consec(["zone", "abigail", "theta", "form", "libe", "zas", "theta", "abigail"], 2) --> "abigailtheta"
#
# n being the length of the string array, if n = 0 or k > n or k <= 0 return "".


我的解答:
  
def consecutive_string(lis, k):
result = ''
if k > 0 and len(lis) >= k:
for i in range(len(lis) - k + 1):
s = ''.join(lis[i:i + k])
if len(s) > len(result):
result = s
return result
原文地址:https://www.cnblogs.com/wlj-axia/p/12672620.html