Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public String[] findWords(String[] words) {
- ArrayList<String> res = new ArrayList<String>();
- HashSet<Character> top = new HashSet<Character>();
- String a = "qwertyuiopQWERTYUIOP";
- for (int i = 0; i < a.length(); i++){
- top.add(a.charAt(i));
- }
- HashSet<Character> mid = new HashSet<Character>();
- String b = "asdfghjklASDFGHJKL";
- for (int i = 0; i < b.length(); i++){
- mid.add(b.charAt(i));
- }
- HashSet<Character> bot = new HashSet<Character>();
- String c = "zxcvbnmZXCVBNM";
- for (int i = 0; i < c.length(); i++){
- bot.add(c.charAt(i));
- }
- for (int i = 0; i < words.length; i++){
- int wordLength = words[i].length();
- int checkTop = 0;
- int checkMid = 0;
- int checkBot = 0;
- for (int j = 0; j < words[i].length(); j++){
- if (top.contains(words[i].charAt(j))){
- checkTop++;
- }
- else if (mid.contains(words[i].charAt(j))){
- checkMid++;
- }
- else{
- checkBot++;
- }
- }
- if (checkTop == wordLength || checkMid == wordLength || checkBot == wordLength){
- res.add(words[i]);
- }
- checkTop = 0;
- checkMid = 0;
- checkBot = 0;
- }
- String[] result = new String[res.size()];
- return res.toArray(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement