Find Words Containing Character

easy string

Problem

You are given a list of strings words and a character x. Return a list of the indices of the words that contain the character x. The answer may be returned in any order.

Inputwords = ["leet","code"], x = "e"
Output[0,1]
"leet" contains 'e' and so does "code", so both indices 0 and 1 are returned.

def find_words_containing(words, x):
    result = []
    for i, w in enumerate(words):
        if x in w:
            result.append(i)
    return result
function findWordsContaining(words, x) {
  const result = [];
  for (let i = 0; i < words.length; i++) {
    if (words[i].includes(x)) {
      result.push(i);
    }
  }
  return result;
}
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            if (words[i].indexOf(x) != -1) {
                result.add(i);
            }
        }
        return result;
    }
}
vector<int> findWordsContaining(vector<string>& words, char x) {
    vector<int> result;
    for (int i = 0; i < (int)words.size(); i++) {
        if (words[i].find(x) != string::npos) {
            result.push_back(i);
        }
    }
    return result;
}
Time: O(total characters) Space: O(1) extra