Simple Javacsript solution


  • 0
    K
    var replaceWords = function(dict, sentence) {
        var spliteds = sentence.split(' ');
        for (var i = 0; i < spliteds.length; i++) {
            for (var word in dict) {
                if (spliteds[i].indexOf(dict[word]) === 0) {
                    spliteds[i] = dict[word];
                    break;
                }
            }
        }
        return spliteds.join(' ');
    };
    

Log in to reply
 

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