题解 | #单词消消乐#

单词消消乐

http://www.nowcoder.com/practice/abb14fd6e1a34b0fb8016dfd7a99dfc5

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param Words string字符串一维数组 
# @return string字符串
#
class Solution:
    def WordsMerge(self, Words):
    # write code here
        tmp = ''
        tmp2 = ''
        for i in range(0, len(Words)):
            if i == 0:
                tmp = Words[0]
            else:
                tmp = tmp[::-1]
                a = len(tmp)
                tmp2 = Words[i]
                while a > 0:
                    if tmp[0] == tmp2[0]:
                        tmp = tmp[1:]
                        tmp2 = tmp2[1:]
                    a -= 1
                tmp = tmp[::-1] + tmp2
        return tmp
            
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务