题解 | #牛族寻找祖先#
牛族寻找祖先
https://www.nowcoder.com/practice/eea77a55616f4961801796c7d36369db
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param names string字符串一维数组 # @return string字符串 # class Solution: def findAncestor(self , names: List[str]) -> str: # write code here com=names[0] for item in names[1:]: j,k=0,0 while j<len(com) and k<len(com): if com[j]==item[k]: j+=1 k+=1 else: break com=com[:j] if len(com)==0: return "" return com