FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-algorithms/src/KeyBoardRow.java at master · anishLearnsToCode/leetcode-algorithms · GitHub
anishLearnsToCode
/
leetcode-algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
17
Star
98
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-algorithms
/
src
/
KeyBoardRow.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (60 loc) · 2.07 KB
Breadcrumbs
leetcode-algorithms
/
src
/
KeyBoardRow.java
Copy path
File metadata and controls
68 lines (60 loc) · 2.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
public
class
KeyBoardRow
{
private
static
final
Map
<
Character
,
Integer
>
alphabetPosition
=
new
HashMap
<>();
static
{
alphabetPosition
.
put
(
'Q'
,
1
);
alphabetPosition
.
put
(
'W'
,
1
);
alphabetPosition
.
put
(
'E'
,
1
);
alphabetPosition
.
put
(
'R'
,
1
);
alphabetPosition
.
put
(
'T'
,
1
);
alphabetPosition
.
put
(
'Y'
,
1
);
alphabetPosition
.
put
(
'U'
,
1
);
alphabetPosition
.
put
(
'I'
,
1
);
alphabetPosition
.
put
(
'O'
,
1
);
alphabetPosition
.
put
(
'P'
,
1
);
alphabetPosition
.
put
(
'A'
,
2
);
alphabetPosition
.
put
(
'S'
,
2
);
alphabetPosition
.
put
(
'D'
,
2
);
alphabetPosition
.
put
(
'F'
,
2
);
alphabetPosition
.
put
(
'G'
,
2
);
alphabetPosition
.
put
(
'H'
,
2
);
alphabetPosition
.
put
(
'J'
,
2
);
alphabetPosition
.
put
(
'K'
,
2
);
alphabetPosition
.
put
(
'L'
,
2
);
alphabetPosition
.
put
(
'Z'
,
3
);
alphabetPosition
.
put
(
'X'
,
3
);
alphabetPosition
.
put
(
'C'
,
3
);
alphabetPosition
.
put
(
'V'
,
3
);
alphabetPosition
.
put
(
'B'
,
3
);
alphabetPosition
.
put
(
'N'
,
3
);
alphabetPosition
.
put
(
'M'
,
3
);
}
public
static
String
[]
findWords
(
String
[]
words
) {
List
<
String
>
result
=
new
ArrayList
<>();
for
(
String
word
:
words
) {
if
(
singleRowWord
(
word
.
toUpperCase
())) {
result
.
add
(
word
);
}
}
return
arrayListToArray
(
result
);
}
private
static
String
[]
arrayListToArray
(
List
<
String
>
list
) {
String
[]
result
=
new
String
[
list
.
size
()];
for
(
int
index
=
0
;
index
<
result
.
length
;
index
++) {
result
[
index
] =
list
.
get
(
index
);
}
return
result
;
}
private
static
boolean
singleRowWord
(
String
word
) {
int
row
=
alphabetPosition
.
get
(
word
.
charAt
(
0
));
for
(
int
index
=
1
;
index
<
word
.
length
() ;
index
++) {
if
(
row
!=
alphabetPosition
.
get
(
word
.
charAt
(
index
))) {
return
false
;
}
}
return
true
;
}
}
Back
|
FazBrowse Home
|
New Git URL