Straightforward Short Python


  • 0
    S
        dict = set(dict)
        sentence = sentence.split(' ')
        
        for idx in range(len(sentence)):
            for i in range(1, len(sentence[idx])+1):
                tmp = sentence[idx]
                if tmp[:i] in dict:
                    sentence[idx] = tmp[:i]
                    break
        return ' '.join(sentence)

Log in to reply
 

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