FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode804.java at master · wpq2014/JavaArithmetic · GitHub
wpq2014
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode804.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (21 loc) · 808 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode804.java
Copy path
File metadata and controls
25 lines (21 loc) · 808 Bytes
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
package
LeetCode
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
Set
;
class
LeetCode804
{
private
String
[]
morse
= {
".-"
,
"-..."
,
"-.-."
,
"-.."
,
"."
,
"..-."
,
"--."
,
"...."
,
".."
,
".---"
,
"-.-"
,
".-.."
,
"--"
,
"-."
,
"---"
,
".--."
,
"--.-"
,
".-."
,
"..."
,
"-"
,
"..-"
,
"...-"
,
".--"
,
"-..-"
,
"-.--"
,
"--.."
};
public
int
uniqueMorseRepresentations
(
String
[]
words
) {
Set
<
String
>
set
=
new
HashSet
<>();
for
(
String
word
:
words
) {
set
.
add
(
getMorse
(
word
));
}
return
set
.
size
();
}
// 将每个字符翻译成摩斯密码
private
String
getMorse
(
String
str
) {
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++) {
sb
.
append
(
morse
[
str
.
charAt
(
i
) -
'a'
]);
}
return
sb
.
toString
();
}
}
Back
|
FazBrowse Home
|
New Git URL