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 ...
随机推荐
- poj 1035 纯正的字符串水
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22673 Accepted: 8258 De ...
- linux sort的用法
sort -n 表示按照数字 sort -k 表示第几列 sort -t : 表示按照:来分列 sort -r 表示从大到小排列
- PHP实现RSA签名生成订单功能【支付宝示例】
//组合签名 $a=time(); $b=substr($a, 1); //生成随机订单号 $orderid= $b.mt_rand(10000,99999); //合作身份者id,以2088开头的1 ...
- 洛谷 最小费用最大流 模板 P3381
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...
- CF10D LCIS (动态规划)
题目链接 Solution 动态规划. 令 \(f_{i,j}\) 表示 \(a\) 数组前 \(i\) 个和 \(b\) 数组前 \(j\) 所得的最长的 LCIS . 转移很好想: \(a_i!= ...
- Welcome to Workrave
Welcome to Workrave Workrave is a free program that assists in the recovery and prevention of Repeti ...
- Windows7下的Run运行命令一览表
按住Windows键(就是左边Ctrl和Alt之间那个印windows徽标的键,简称Win键)+R,即可弹出运行对话框,在里面输入黑体字符即可运行相应程序.相比XP这次新增了不少新东西. 添加/删除程 ...
- 重量WeightFormatUtil辅助类
package com.jlb.scan.util; import java.text.DecimalFormat; public class WeightFormatUtil { public st ...
- c# 动态调用webservice 转录一下
1. client call method [上线的话也只是需要改一下wsdl地址就可以了] /// <summary> /// 动态webservice调用 /// </sum ...
- Windows注册与删除mysql服务
1.删除服务: (1)采用windows自带的服务管理工具:参考:http://www.cnblogs.com/qlqwjy/p/8010598.html sc delete MySQL57 (2)m ...