Strobogrammatic Number II -- LeetCode
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;
}
};
Strobogrammatic Number II -- LeetCode的更多相关文章
- [Locked] Strobogrammatic Number & Strobogrammatic Number II & Strobogrammatic Number III
Strobogrammatic Number A strobogrammatic number is a number that looks the same when rotated 180 deg ...
- [LeetCode] Strobogrammatic Number II 对称数之二
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- LeetCode Strobogrammatic Number II
原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a n ...
- [LeetCode] 247. Strobogrammatic Number II 对称数II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- [LeetCode#247] Strobogrammatic Number II
Problem: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked a ...
- 247. Strobogrammatic Number II
题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...
- [Swift]LeetCode247.对称数 II $ Strobogrammatic Number II
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- 247. Strobogrammatic Number II输出所有对称数字
[抄题]: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at u ...
- Ugly Number II leetcode java
问题描述: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime fa ...
随机推荐
- 一道简单的CTFpython沙箱逃逸题目
看了几天的ssti注入然后了解到有python沙箱逃逸 学过ssti注入的话python沙箱逃逸还是很容易理解的. 看一道CTF题目,源码的话我改了改,一开始不能用,直接在py2上运行就好. 题目要求 ...
- 1、python 循环控制
案例1: lucky_num = 19 input_num = int(input("Input the guess number:")) if input_num == luc ...
- python import模块熟悉方法
python import导入的可用模块很多,新增速度较快,无法一次性全部掌握. 掌握熟悉一种模块的方法是非常有价值的技能. 探究模块可以从python解释器入手,具体流程记录如下: 以os模块为例: ...
- Opencv3.4.5安装包
这个资源是Opencv3.4.5安装包,包括Windows软件包,Android软件包,IOS软件包,还有opencv的源代码:需要的下载吧. 点击下载
- U-Net卷积神经网络
由于项目需要,用U-NET跑一个程序来对医学影像进行分割(segmentation),因此跑去看了下这篇论文(paper),下面会介绍一下U-Net的框架及要点,如果哪里有写的不对的,或者好的建议,欢 ...
- windows安装 Nodejs,NPM, CNPM
1, dowload Nodejs from : http://nodejs.cn/download/ 下载完毕后,可以安装node,建议不要安装在系统盘(本例安装在 D:\vueProject) ...
- [NC189A]数字权重
题目大意:有一个$n$位的数,设第$i$位为$a_i$(最高位为$a_1$).问满足$(\sum\limits_{i=2}^n(a_i-a_{i-1}))==k$的数的个数(不含前导零) 题解:发现$ ...
- gulp技巧总结
1. gulp.dest 会自动创建目录 gulp.dest(dir),若dir不存在,gulp会自动创建它 2. gulp.src copy具名路径(即不子目录**的路径)的文件,不会保留文件夹路径 ...
- 论文笔记《Deep Hand: How to Train a CNN on 1 Million Hand Images When Your Data Is Continuous and Weakly Labelled》
一.概述 这个是最近的核心工作了,基本上都是靠着这篇paper的model过日子了啊.. 论文主要讲的是hand gesture recognition,实际上是用googlenet做的一个class ...
- ss安装教程
https://teddysun.com/342.html 加速 wget –no-check-certificate https://github.com/teddysun/across/raw/m ...