-
Notifications
You must be signed in to change notification settings - Fork 0
/
500_KeyboardRow_1.java
29 lines (29 loc) · 1.41 KB
/
500_KeyboardRow_1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public String[] findWords(String[] words) {
int flag1 = 0, flag2 = 0, flag3 = 0;
List<String> result = new ArrayList<String>();
for(String aa : words)
{
char[] find = aa.toCharArray();
for(char ss: find)
{
if(ss == 'Q'||ss == 'q'||ss == 'W'||ss == 'w'||ss == 'E'||ss == 'e'||ss == 'R'||ss == 'r'||ss == 'T'||ss == 't'||ss == 'Y'||ss == 'y'||ss == 'U'||ss == 'u'||ss == 'I'||ss == 'i'||ss == 'O'||ss == 'o'||ss == 'P'||ss == 'p')
flag1 = 1;
if(ss == 'A'||ss == 'a'||ss == 'S'||ss == 's'||ss == 'D'||ss == 'd'||ss == 'F'||ss == 'f'||ss == 'G'||ss == 'g'||ss == 'H'||ss == 'h'||ss == 'J'||ss == 'j'||ss == 'K'||ss == 'k'||ss == 'L'||ss == 'l')
flag2 = 1;
if(ss == 'Z'||ss == 'z'||ss == 'X'||ss == 'x'||ss == 'C'||ss == 'c'||ss == 'V'||ss == 'v'||ss == 'B'||ss == 'b'||ss == 'N'||ss == 'n'||ss == 'M'||ss == 'm')
flag3 = 1;
}
if(flag1 == 1 && flag2 == 0 && flag3 == 0)
result.add(aa);
if(flag1 == 0 && flag2 == 1 && flag3 == 0)
result.add(aa);
if(flag1 == 0 && flag2 == 0 && flag3 == 1)
result.add(aa);
flag1 = 0;
flag2 = 0;
flag3 = 0;
}
return (String[])result.toArray(new String[0]);
}
}