本文共 848 字,大约阅读时间需要 2 分钟。
This problem can be solved easily once you find the regularities :-) has done it for you. You may refer to its Python version. I rewrite it in C++ below.
1 class Solution { 2 public: 3 vectorfindStrobogrammatic(int n) { 4 vector strobos; 5 if (n & 1) strobos = { "0", "1", "8"}; 6 else strobos = { ""}; 7 vector bases = { "00", "11", "88", "69", "96"}; 8 int m = bases.size(); 9 while (n > 1) {10 n -= 2;11 vector 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 };
转载地址:http://qettx.baihongyu.com/