Very imp to learn java syntax
From https://leetcode.com/problems/keyboard-row/#/description
public class Solution {
public String[] findWords(String[] words) {
List<String> ans = new ArrayList<>(); // ******
for ( String s : words){ // **** for each loop on String[]
if (check("qwertyuiop", s) || check("asdfghjkl", s) || check("zxcvbnm", s)) {
ans.add(s);
}
}
return ans.toArray(new String[0]); // convert list<String> to String[]
}
public boolean check(String keyboardStr, String str){
str = str.toLowerCase(); // convert string to lower case
for ( char c : str.toCharArray()){ // for each loop for every characher in a string **
if ( keyboardStr.indexOf(c) == -1){ // check if a char is present in a string **
return false;
}
}
return true;
}
}