FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/code/lc17.java at master · mJackie/leetcode · GitHub
mJackie
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
135
Star
405
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
code
/
lc17.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (33 loc) · 1.11 KB
Breadcrumbs
leetcode
/
code
/
lc17.java
Copy path
File metadata and controls
35 lines (33 loc) · 1.11 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
package
code
;
import
java
.
util
.
List
;
import
java
.
util
.
Vector
;
/*
* 17. Letter Combinations of a Phone Number
* 题意:手机键盘字母输入
* 难度:Medium
* 思路:思路记一下,每次放到vector中,遍历vector,加上所有的可能
* 分类:String, Backtracking
*/
public
class
lc17
{
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
letterCombinations
(
"23"
).
toString
());
}
public
static
List
<
String
>
letterCombinations
(
String
digits
) {
Vector
<
String
>
res
=
new
Vector
<>();
if
(
digits
.
length
()==
0
)
return
res
;
String
[]
charmap
= {
""
,
""
,
"abc"
,
"def"
,
"ghi"
,
"jkl"
,
"mno"
,
"pqrs"
,
"tuv"
,
"wxyz"
};
res
.
add
(
""
);
for
(
int
i
=
0
;
i
<
digits
.
length
();
i
++) {
int
n
=
digits
.
charAt
(
i
)-
'0'
;
Vector
<
String
>
temp_res
=
new
Vector
<>();
for
(
int
j
=
0
;
j
<
charmap
[
n
].
length
();
j
++) {
for
(
int
k
=
0
;
k
<
res
.
size
();
k
++) {
temp_res
.
add
(
res
.
get
(
k
)+
charmap
[
n
].
charAt
(
j
));
}
}
res
=
temp_res
;
}
return
res
;
}
}
Back
|
FazBrowse Home
|
New Git URL