728x90
반응형
✨ 문제
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.
https://leetcode.com/problems/number-of-good-pairs/description/
✨ 최종코드
class Solution {
public List<Integer> findWordsContaining(String[] words, char x) {
List<Integer> indices = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
if (words[i].indexOf(x) != -1) {
indices.add(i);
}
}
return indices;
}
}
728x90
반응형