当前位置:网站首页>2022.7.7-----leetcode.648

2022.7.7-----leetcode.648

2022-07-07 21:53:00 路Lu727

 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;
    }

原网站

版权声明
本文为[路Lu727]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_60466670/article/details/125667232