Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class Solution {
  2. public String[] findWords(String[] words) {
  3. ArrayList<String> res = new ArrayList<String>();
  4. HashSet<Character> top = new HashSet<Character>();
  5. String a = "qwertyuiopQWERTYUIOP";
  6. for (int i = 0; i < a.length(); i++){
  7. top.add(a.charAt(i));
  8. }
  9. HashSet<Character> mid = new HashSet<Character>();
  10. String b = "asdfghjklASDFGHJKL";
  11. for (int i = 0; i < b.length(); i++){
  12. mid.add(b.charAt(i));
  13. }
  14. HashSet<Character> bot = new HashSet<Character>();
  15. String c = "zxcvbnmZXCVBNM";
  16. for (int i = 0; i < c.length(); i++){
  17. bot.add(c.charAt(i));
  18. }
  19.  
  20. for (int i = 0; i < words.length; i++){
  21. int wordLength = words[i].length();
  22. int checkTop = 0;
  23. int checkMid = 0;
  24. int checkBot = 0;
  25. for (int j = 0; j < words[i].length(); j++){
  26. if (top.contains(words[i].charAt(j))){
  27. checkTop++;
  28. }
  29. else if (mid.contains(words[i].charAt(j))){
  30. checkMid++;
  31. }
  32. else{
  33. checkBot++;
  34. }
  35. }
  36. if (checkTop == wordLength || checkMid == wordLength || checkBot == wordLength){
  37. res.add(words[i]);
  38. }
  39. checkTop = 0;
  40. checkMid = 0;
  41. checkBot = 0;
  42. }
  43. String[] result = new String[res.size()];
  44. return res.toArray(result);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement