2942: Find-Words-Containing-Character
Easy
table of contents
Literally just iterate through all the letters in each
word
of words
and append the index to the end
of ans
when word[i] == x
.
code
class Solution {
public:
<int> findWordsContaining(vector<string>& words, char x) {
vector<int> ans;
vectorfor (int i = 0; i < words.size(); ++i) {
for (char& c : words[i]) {
if (c == x) {
.push_back(i);
ansbreak;
}
}
}
return ans;
}
};