Short java code

  • 0
    class Solution {
        public String replaceWords(List<String> dict, String sentence) {
            String [] str = sentence.trim().split("\\s+");
            for(int i=0 ; i < dict.size(); i++){
               for(int j=0; j<str.length;j++){
                   if(str[j].indexOf(dict.get(i)) ==0){
           String res="";
           for(String s : str){
                res+=s+" ";
            }return res.trim();

Log in to reply

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