博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Strobogrammatic Number II
阅读量:7107 次
发布时间:2019-06-28

本文共 929 字,大约阅读时间需要 3 分钟。

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     vector
findStrobogrammatic(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 };

 

转载于:https://www.cnblogs.com/jcliBlogger/p/4713146.html

你可能感兴趣的文章
Ubuntu Linux訪问小米手机存储卡
查看>>
Python中字符串的Format用法。
查看>>
linux常用命令大全[转]
查看>>
Zabbix实现自动发现端口并监控
查看>>
Mybatis 动态 SQL
查看>>
struct 方法使用
查看>>
【从零之三(更)】自己定义类中调用讯飞语音包错误解决的方法
查看>>
数据结构之链表单向操作总结
查看>>
BZOJ3795 : 魏总刷DP
查看>>
netty4与protocol buffer结合简易教程
查看>>
vim、gvim在windows下中文乱码的终极解决方式
查看>>
Linux系统故障排除
查看>>
自己定义控件----倒计时控件
查看>>
ubuntu16.04与mysql的运维注意事项
查看>>
我眼中的ASP.NET Core之微服务 (二)
查看>>
Java 集合并交补
查看>>
MySql和Sql的单行注释和多行注释的区别
查看>>
Cannot create __weak reference in file using manual reference counting
查看>>
(zhuan) Variational Autoencoder: Intuition and Implementation
查看>>
PHI 数据库简介
查看>>