2942: Find-Words-Containing-Character
Easy
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;
}
};