fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] words = {"leet","code"};
  13. char x = 'e';
  14. System.out.println(findWordsContaining(words,x));
  15.  
  16. }
  17.  
  18. static List<Integer> findWordsContaining(String[] words, char x) {
  19. List<Integer> list = new ArrayList<>();
  20.  
  21. int n = words.length;
  22.  
  23. for(int i=0;i<n;i++){
  24. if(check(words[i],x)){
  25. list.add(i);
  26. }
  27. }
  28.  
  29. return list;
  30. }
  31.  
  32.  
  33. static boolean check(String word,char target){
  34.  
  35. for(int i=0;i<word.length();i++){
  36.  
  37. char ch = word.charAt(i);
  38.  
  39. if(ch == target){
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. }
Success #stdin #stdout 0.1s 54624KB
stdin
Standard input is empty
stdout
[0, 1]