출처 : https://leetcode.com/problems/find-words-containing-character/
You are given a 0-indexed array of strings words
and a character x
.
Return an array of indices representing the words that contain the character x
.
Note that the returned array may be in any order.
class Solution {
public List<Integer> findWordsContaining(String[] words, char x) {
List<Integer> res = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words[i].length(); j++) {
if (words[i].charAt(j) == x) {
res.add(i);
break;
}
}
}
return res;
}
}