-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardRow.java
More file actions
50 lines (48 loc) · 1.61 KB
/
KeyboardRow.java
File metadata and controls
50 lines (48 loc) · 1.61 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<<<<<<< HEAD
//500. Keyboard Row
class Solution {
public String[] findWords(String[] words) {
String row1 = "qwertyuiop";
String row2 = "asdfghjkl";
String row3 = "zxcvbnm";
List<String> list = new ArrayList<>();
for(String word : words){
String lower = word.toLowerCase();
String row = (row1.contains(lower.charAt(0) + "")) ? row1 :
(row2.contains(lower.charAt(0) + "")) ? row2 : row3;
boolean isValid = true;
for(char c : lower.toCharArray()){
if(!row.contains(c + "")){
isValid = false;
break;
}
}
if(isValid) list.add(word);
}
return list.toArray(new String[0]);
}
=======
//500. Keyboard Row
class Solution {
public String[] findWords(String[] words) {
String row1 = "qwertyuiop";
String row2 = "asdfghjkl";
String row3 = "zxcvbnm";
List<String> list = new ArrayList<>();
for(String word : words){
String lower = word.toLowerCase();
String row = (row1.contains(lower.charAt(0) + "")) ? row1 :
(row2.contains(lower.charAt(0) + "")) ? row2 : row3;
boolean isValid = true;
for(char c : lower.toCharArray()){
if(!row.contains(c + "")){
isValid = false;
break;
}
}
if(isValid) list.add(word);
}
return list.toArray(new String[0]);
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}