Leetcode | 2942. Find Words Containing Character | Easy | Java Solution

preview_player
Показать описание
This video has the Problem Statement, Solution Walk-through and Code for the Leetcode Question 2942. Find Words Containing Character, with Time Complexity of O(m.n) and Space Complexity of O(1).

Time Stamps ⏱️:
0:00 - Problem Statement
1:03 - Solving the Problem
2:37 - Code
5:08 - Time and Space Complexity
____
2942. Find Words Containing Character
Leetcode Find Words Containing Character
Find Words Containing Character
Find Words Containing Character Leetcode Solution
Find Words Containing Character Java Solution
Leetcode 2942
Leetcode 2942 solution
Leetcode Solutions Playlist
Leetcode Java Solutions Playlist
Leetcode Easy Solutions
Developer Docs Leetcode
Find Words Containing Character Developer Docs

Hashtags:
#leetcode #leetcodesolution #java #leetcodedailychallenge
Рекомендации по теме
Комментарии
Автор

Won't be space complexity equal to O(n) as well, since if each of the word in words contains x, then total indices would be equal to words array size? Correct me if I am wrong.

adityamore
Автор

Here instead of converting the String to character array, you can simply do the same check using indexOf(ch) method. It returns -1 when there is no character present in the String.
The code for the same would be :

class Solution {
public List<Integer> findWordsContaining(String[] words, char x) {
List<Integer> resultArray = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
if (words[i].indexOf(x) != -1) {
resultArray.add(i);
}
}
return resultArray;
}
}

SahilShaikh-mktz