forked from jsjtzyy/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC247_StrobogrammaticNumberII.java
More file actions
58 lines (57 loc) · 1.36 KB
/
LC247_StrobogrammaticNumberII.java
File metadata and controls
58 lines (57 loc) · 1.36 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
51
52
53
54
55
56
57
58
import java.util.*;
/*
use recursion
*/
public class LC247_StrobogrammaticNumberII {
public List<String> findStrobogrammatic(int n) {
List<String> res = new ArrayList<>();
if(n == 0) return res;
if(n == 1) {
res.add("0");
res.add("1");
res.add("8");
return res;
}
if(n == 2) {
res.add("11");
res.add("69");
res.add("88");
res.add("96");
return res;
}
List<String> list = helper(n - 2);
for(String str : list){
res.add("1" + str + "1");
res.add("8" + str + "8");
res.add("6" + str + "9");
res.add("9" + str + "6");
}
return res;
}
public List<String> helper(int n) {
List<String> res = new ArrayList<>();
if(n == 1) {
res.add("0");
res.add("1");
res.add("8");
return res;
}
if(n == 2) {
res.add("00");
res.add("11");
res.add("69");
res.add("88");
res.add("96");
return res;
}
List<String> list = helper(n - 2);
for(String str : list){
res.add("0" + str + "0");
res.add("1" + str + "1");
res.add("8" + str + "8");
res.add("6" + str + "9");
res.add("9" + str + "6");
}
return res;
}
}