Keyboard Row LeetCode solution in Java

1
class Solution {
2
public String[] findWords(String[] words) {
3
String s1 = "qwertyuiopQWERTYUIOP";
4
String s2 = "asdfghjklASDFGHJKL";
5
String s3 = "zxcvbnmZXCVBNM";
6
ArrayList<String> list = new ArrayList<>();
7
for (int i = 0; i < words.length; i++) {
8
int count1 = 0, count2 = 0, count3 = 0, len = words[i].length();
9
for (int j = 0; j < len; j++) {
10
if (s1.contains(Character.toString(words[i].charAt(j)))) count1++;
11
else if (s2.contains(Character.toString(words[i].charAt(j)))) count2++;
12
else if (s3.contains(Character.toString(words[i].charAt(j)))) count3++;
13
if (count1 == len || count2 == len || count3 == len) list.add(words[i]);
14
}
15
}
16
String ans[] = new String[list.size()];
17
list.toArray(ans);
18
return ans;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0