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"]
.
class Solution {
public:
char num[] = {'', '', '', '', ''};
char rotate(char num) {
if (num == '' || num == '' || num == '')
return num;
else if (num == '') return '';
else return '';
}
void help(vector<string>& res, string& cand, int curInd) {
if (cand.size() & && curInd == (cand.size() - ) / ) {
cand[curInd] = ''; res.push_back(cand);
cand[curInd] = ''; res.push_back(cand);
cand[curInd] = ''; res.push_back(cand);
} else {
int st = curInd ? : ;
for (; st < ; st++) {
cand[curInd] = num[st];
cand[cand.size() - curInd - ] = rotate(num[st]);
if (curInd == (cand.size() - ) / ) res.push_back(cand);
else help(res, cand, curInd + );
}
}
}
vector<string> findStrobogrammatic(int n) {
vector<string> res;
if (n < ) return res;
string cand(n, '');
help(res, cand, );
return res;
}
};