Leetcode 247 Solution

This article provides solution to leetcode question 247 (strobogrammatic-number-ii)

https://leetcode.com/problems/strobogrammatic-number-ii

Solution

class Solution { public: vector<string> findStrobogrammatic(int n, bool allowLeadingZero) { vector<string> res;
if (n == 0) res.push_back(""); else if (n == 1) { res.push_back("0"); res.push_back("1"); res.push_back("8"); return res; } else { auto subres = findStrobogrammatic(n - 2, true); for (auto sub : subres) { if (allowLeadingZero) res.push_back("0" + sub + "0"); res.push_back("1" + sub + "1"); res.push_back("6" + sub + "9"); res.push_back("8" + sub + "8"); res.push_back("9" + sub + "6"); } }
return res; }
vector<string> findStrobogrammatic(int n) { return findStrobogrammatic(n, false); } };