美文网首页
5380. String Matching in an Arra

5380. String Matching in an Arra

作者: 7ccc099f4608 | 来源:发表于2020-04-12 23:24 被阅读0次

https://leetcode-cn.com/problems/string-matching-in-an-array/

代码参考 & 解释,引用自:
https://leetcode-cn.com/problems/number-of-ways-to-paint-n-x-3-grid/solution/shu-xue-jie-jue-fei-chang-kuai-le-by-lindsaywong/

image.png

(图片来源https://leetcode-cn.com/problems/string-matching-in-an-array/

日期 是否一次通过 comment
2020-03-23 0

public List<String> stringMatching(String[] words) {
        if(words == null || words.length < 1) {
            return new ArrayList<>();
        }

        List<String> res = new ArrayList<>();

        String allS = String.join(",", words);
        for(String s : words) {
            if(allS.indexOf(s) != allS.lastIndexOf(s)) {
                res.add(s);
            }
        }

        return res;
    }

相关文章

网友评论

      本文标题:5380. String Matching in an Arra

      本文链接:https://www.haomeiwen.com/subject/glaimhtx.html