题解 | #牛群名字编码#

牛群名字编码

https://www.nowcoder.com/practice/9e86301a87954987932f3c7869b5a610

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param names string字符串一维数组
# @return int整型
#
class Solution:
    def minimum_encoding_length(self, names: List[str]) -> int:
        # write code here
        indices = [name + "#" for name in names]
        indices.sort(key=lambda x: len(x))
        indices = indices + ["#"]
        count = 0
        for i in range(len(indices) - 1):
            for j in range(i + 1, len(indices)):
                if indices[j].endswith(indices[i]):
                    break
            if j == len(indices) - 1:
                count += len(indices[i])
        return count

全部评论

相关推荐

点赞 评论 收藏
分享
05-22 09:23
门头沟学院 Java
点赞 评论 收藏
分享
nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务