#Replace Words

class Solution(object):
    def replaceWords(self, dictionary, sentence):
        """
        :type dictionary: List[str]
        :type sentence: str
        :rtype: str
        """
        dictionary_set = set(dictionary)
        # max length of the roots available
        max_root_len = len(max(dictionary_set, key=len))
        sent = []
        for word in sentence.split(" "):
            for idx in range(len(word)):
                if idx <= max_root_len:
                    if word[:idx] in dictionary_set:
                        # find the best solution
                        word_set = set([word[:idx]])
                        word = min(word_set & dictionary_set)
                        break
                else:
                    break
            sent.append(word)
        return " ".join(sent)
d0a9fbb77cc57a46c6b78999726297eaa4d3d0f9
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def replaceWords(self, dictionary, sentence):
        """
        :type dictionary: List[str]
        :type sentence: str
        :rtype: str
        """
        dictionary_set = set(dictionary)
        max_root_len = len(max(dictionary_set, key=len))
        sent = []
        for word in sentence.split(' '):
            for idx in range(len(word)):
                if idx <= max_root_len:
                    if word[:idx] in dictionary_set:
                        word_set = set([word[:idx]])
                        word = min(word_set & dictionary_set)
                        break
                else:
                    break
            sent.append(word)
        return ' '.join(sent)

#Replace Words

class Solution(object):
    def replaceWords(self, dictionary, sentence):
        """
        :type dictionary: List[str]
        :type sentence: str
        :rtype: str
        """
        dictionary_set = set(dictionary)
        # max length of the roots available
        max_root_len = len(max(dictionary_set, key=len))
        sent = []
        for word in sentence.split(" "):
            for idx in range(len(word)):
                if idx <= max_root_len:
                    if word[:idx] in dictionary_set:
                        # find the best solution
                        word_set = set([word[:idx]])
                        word = min(word_set & dictionary_set)
                        break
                else:
                    break
            sent.append(word)
        return " ".join(sent)