# [LeetCode] Strobogrammatic Number II

This problem can be solved easily once you find the regularities :-) This link has done it for you. You may refer to its Python version. I rewrite it in C++ below.

 1 class Solution {
2 public:
3     vector<string> findStrobogrammatic(int n) {
4         vector<string> strobos;
5         if (n & 1) strobos = {"0", "1", "8"};
6         else strobos = {""};
7         vector<string> bases = {"00", "11", "88", "69", "96"};
8         int m = bases.size();
9         while (n > 1) {
10             n -= 2;
11             vector<string> temp;
12             for (string strobo : strobos)
13                 for (int i = (n < 2 ? 1 : 0); i < m; i++)
14                     temp.push_back(bases[i].substr(0, 1) + strobo + bases[i].substr(1));
15             swap(temp, strobos);
16         }
17         return strobos;
18     }
19 };

|
9月前
|

Leetcode 313. Super Ugly Number

80 1
|
2月前
|

LeetCode 题目 65：有效数字（Valid Number）【python】
LeetCode 题目 65：有效数字（Valid Number）【python】
37 5
|
3月前
|

【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
【LeetCode力扣】单调栈解决Next Greater Number（下一个更大值）问题
25 0
|
9月前
|

Leetcode Single Number II （面试题推荐）

30 0
|

LeetCode 414. Third Maximum Number

79 0
|

LeetCode 405. Convert a Number to Hexadecimal

74 0
|
API
LeetCode 375. Guess Number Higher or Lower II

93 0
|
API
LeetCode 374. Guess Number Higher or Lower

64 0
|

LeetCode 321. Create Maximum Number

57 0
|

LeetCode 313. Super Ugly Number

83 0