Skip to content

Commit 8082ce0

Browse files
author
liwentian
committed
fd
1 parent a43e4c1 commit 8082ce0

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191
|241|[Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/DifferenceWaysToAddParentheses.java)||
192192
|242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ValidAnagram.java)|100|
193193
|243|[Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ShortestWordDistance.java)|80|
194-
|246|[Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/StrobogrammaticNumber.java)|70|这是一个系列,多看两遍|
194+
|246|[Strobogrammatic Number](https://leetcode.com/problems/strobogrammatic-number/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/StrobogrammaticNumber.java)|70|#247一个系列,多看两遍|
195+
|247|[Strobogrammatic Number II](https://leetcode.com/problems/strobogrammatic-number-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/StrobogrammaticNumberII.java)|70|多看两遍|
195196
|250|[Count Univalue Subtrees](https://leetcode.com/problems/count-univalue-subtrees/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CountUnivalueSubtrees.java)|70|这题要多做几遍|
196197
|251|[Flatten 2D Vector](https://leetcode.com/problems/flatten-2d-vector/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/Vector2D.java)|100|
197198
|252|[Meeting Rooms](https://leetcode.com/problems/meeting-rooms/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MeetingRooms.java)|100|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.leetcode.google;
2+
3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.LinkedList;
6+
import java.util.List;
7+
8+
/**
9+
* Created by liwentian on 2017/8/31.
10+
*/
11+
12+
public class StrobogrammaticNumberII {
13+
14+
15+
public List<String> findStrobogrammatic(int n) {
16+
return helper(n, n);
17+
}
18+
19+
private List<String> helper(int k, int n) {
20+
if (k == 0) {
21+
return Arrays.asList("");
22+
} else if (k == 1) {
23+
return Arrays.asList("0", "1", "8");
24+
}
25+
List<String> result = new LinkedList<>();
26+
for (String s : helper(k - 2, n)) {
27+
if (k != n) {
28+
result.add("0" + s + "0");
29+
}
30+
31+
result.add("1" + s + "1");
32+
result.add("8" + s + "8");
33+
result.add("6" + s + "9");
34+
result.add("9" + s + "6");
35+
}
36+
return result;
37+
}
38+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.inuker.solution;
2+
3+
/**
4+
* Created by liwentian on 2017/8/31.
5+
*/
6+
7+
/**
8+
* 旋转180度,而不是上下镜像
9+
*/
10+
public class StrobogrammaticNumber {
11+
12+
public boolean isStrobogrammatic(String num) {
13+
for (int i = 0, j = num.length() - 1; i <= j; i++, j--) {
14+
if (!"11 88 00 696".contains(num.charAt(i) + "" + num.charAt(j))) {
15+
return false;
16+
}
17+
}
18+
return true;
19+
}
20+
}

test/src/main/java/com/example/Main.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.leetcode.google.MissingRanges;
55
import com.leetcode.google.SentenceScreenFitting;
66
import com.leetcode.google.ShortestDistanceFromAllBuildings;
7+
import com.leetcode.google.StrobogrammaticNumberII;
78
import com.leetcode.google.UTFValidation;
89
import com.leetcode.google.WordSquares;
910
import com.leetcode.google.ZigzagIterator;
@@ -15,10 +16,10 @@
1516
public class Main {
1617

1718
public static void main(String[] args) {
18-
boolean n = new UTFValidation().validUtf8(new int[] {
19-
197, 130, 1
20-
});
21-
System.out.println(n);
19+
List<String> list = new StrobogrammaticNumberII().findStrobogrammatic(4);
20+
for (String s : list) {
21+
System.out.print(s + " ");
22+
}
2223
}
2324
}
2425

0 commit comments

Comments
 (0)