[코테 풀이] Find Words Containing Character

시내·2024년 6월 10일
0

Q_2942) Find Words Containing Character

출처 : 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; 
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글