1408. String Matching in an Array
Given an array of string words
, return all strings in words
that is a substring of another word. You can return the answer in any order.
A substring is a contiguous sequence of characters within a string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: vector<string> stringMatching(vector<string>& words) { vector<string> res; for(auto& w : words) { bool ok = false; for(auto& ww : words) { if(w == ww) continue; ok = ww.find(w) != string::npos; if(ok) break; } if(ok) res.push_back(w); } return res; } };
|