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/
(图片来源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;
}
网友评论