simple 9 lines python code


  • 0
    S

    simple 9 lines python code. if you have any questions. i'd love to discuss in comment section.

    class Solution(object):
        def replaceWords(self, dict, sentence):
            dict.sort(key = len)
            sentenceList=sentence.split()
            for i in range (len(dict)-1,-1,-1):
                for j in range (len(sentenceList)):
                    if dict[i]==sentenceList[j][:len(dict[i])]:
                        sentenceList[j]=dict[i]
            return " ".join(sentenceList)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.