[抄题]:

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.

Example:

Input:  n = 2
Output: ["11","69","88","96"]

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

当前长度是0或1时需要退出或者返回,所以要新建一个动态数组。

new ArrayList<String>(Arrays.asList(""));

[思维问题]:

不知道怎么控制dfs的长度:

helper(curCount - 2, targetCount)取上一截,然后i取list的size

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

curcount != targetcount时,两端必加0,从中间开始加。

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

helper(curCount - 2, targetCount)取上一截,然后逐渐往外扩展

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

增长回文串也就只有这几种情况:

        res.add("0" + s + "0");
res.add("1" + s + "1");
res.add("6" + s + "9");
res.add("8" + s + "8");
res.add("9" + s + "6");

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public List<String> findStrobogrammatic(int n) {
List<String> result = new ArrayList<String>();
//corner case
if (n < 0) return result;
//return
return getStrobogrammaticNums(n, n);
} public List<String> getStrobogrammaticNums(int curCount, int targetCount) {
//corner case: n = 0 or 1
if (curCount == 0) return new ArrayList<String>(Arrays.asList(""));
if (curCount == 1) return new ArrayList<String>(Arrays.asList("0", "1", "8")); List<String> result = new ArrayList<String>();
List<String> list = getStrobogrammaticNums(curCount - 2, targetCount); //get the new nums into result
for (int i = 0; i < list.size(); i++) {
String cur = list.get(i);
//add 0 from inside if length do not equal
if (curCount != targetCount) result.add("0" + cur + "0");
//add other nums
result.add("1" + cur + "1");
result.add("6" + cur + "9");
result.add("9" + cur + "6");
result.add("8" + cur + "8");
} //return
return result;
}
}

247. Strobogrammatic Number II输出所有对称数字的更多相关文章

  1. [LeetCode] 247. Strobogrammatic Number II 对称数II

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  2. 247. Strobogrammatic Number II

    题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...

  3. [LeetCode#247] Strobogrammatic Number II

    Problem: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked a ...

  4. [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 ...

  5. [LeetCode] Strobogrammatic Number II 对称数之二

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  6. [Swift]LeetCode247.对称数 II $ Strobogrammatic Number II

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  7. LeetCode Strobogrammatic Number II

    原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a n ...

  8. Strobogrammatic Number II -- LeetCode

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  9. binary-tree-level-order-traversal I、II——输出二叉树的数字序列

    I Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to righ ...

随机推荐

  1. SVN远程管理

    1.使用远程桌面连接工具,分别填写连接地址和用户名进行连接 2.紧接着进行安全登录. 3.打开VisualSVN Server Manager工具进行显示已经拥有的项目和分配好的群组管理. 这样子就可 ...

  2. 怎样生成一个顶点迭代器(MItMeshVertex)

    最近修改一个maya中的jlCollisionDeformer工具,该工具有一个明显不足,变形后顶点分布太乱,无法满足生产需求.于是考虑对该变形后的顶点进行平滑处理.既然要做平滑处理就要获取当前点及与 ...

  3. base64图片内容下载转为图片保存

    网页中的base64图片内容下载后,利用PIL转为图片保存 from skimage.io import imread from PIL import Image from cStringIO imp ...

  4. Java中常用类(包装类扩展知识)

    Java常用类有哪些? 八大基本数据类型的包装类 包装类均位于java.lang包中,包装类和基本数据类型的对应关系如下表: 基本数据类型 包装类 byte Byte boolean Boolean ...

  5. FPGA editor 的使用之一 ------ Probe探针

    做FPGA设计经常会用到FPGA editor工具,今天开始总结下使用FPGA editor工具的经验. 1.添加probes 在debug时,经常要分析设计中的某一个信号的状态变化,需要观测这个信号 ...

  6. PyQt5系列教程(六)如何让界面和逻辑分离

    软硬件环境 OS X EI Capitan Python 3.5.1 PyQt 5.5.1 PyCharm 5.0.3 前言 前面的内容我们介绍了利用QtDesigner来设计界面,再通过命令行工具p ...

  7. Python cx_Oracle 安装小记

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,Python cx_Oracle 安装小记 SQLAlchemy 是 Pytho ...

  8. windows的cmd批处理命令及powershell (二)

    1.变量设置 for /l %%i in (1,1,100) do @echo %%i set /a i=500set /a i=%i%+200echo %i%pause ++++++++++++++ ...

  9. JavaScript获取、修改CSS样式合辑

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. leetcode287

    public class Solution { public int FindDuplicate(int[] nums) { ) { ]; ]]; while (slow != fast) { slo ...