Simple Python Soln. in 6 lines

  • 0


    class Solution(object):
        def replaceWords(self, dict, sentence):
            sentlist = sentence.split(" ")
            for i in dict:
                for m, j in enumerate(sentlist):
                    if i == j[:len(i)]:
                        sentlist[m] = i
            return " ".join(sentlist)


Log in to reply

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