247. Strobogrammatic Number II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Find all strobogrammatic numbers that are of length = n.
For example,
Given n = 2, return["11","69","88","96"]
.
public List<String> findStrobogrammatic(int n) {
List<String> res = new ArrayList<>((n & 1) == 0 ? Arrays.asList("") : Arrays.asList("0", "1", "8"));
if (n < 2) {
return res;
}
for (int i = n % 2 + 2; i <= n; i += 2) {
List<String> cur = new ArrayList<>();
for (String s : res) {
if (i != n) {
cur.add("0" + s + "0");
}
cur.add("1" + s + "1");
cur.add("6" + s + "9");
cur.add("8" + s + "8");
cur.add("9" + s + "6");
}
res = cur;
}
return res;
}