当前位置:网站首页>2022.7.7-----leetcode. six hundred and forty-eight

2022.7.7-----leetcode. six hundred and forty-eight

2022-07-07 23:47:00 Lu 727

 public String replaceWords(List<String> dictionary, String sentence) {
        String[] ss=sentence.split(" ");
        int n=ss.length;
        for(int i=0;i<n;i++){
            for(String dic:dictionary){
                if(ss[i].startsWith(dic))
                    ss[i]=dic;
            }
        }
        String ans="";
        for(int i=0;i<n;i++){
            ans+=ss[i];
            if(i!=n-1)
            ans+=" ";
        }
        return ans;
    }

原网站

版权声明
本文为[Lu 727]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072128583182.html