[抄题]:

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. 二维数组的查找(JAVA)

    二维数组查找 解题思路:找到该二维数组的特殊点,易知该二维数组左下角的那个点很特殊.从这个点往右看,数值都在变大:而往上看,数值都在变小.所以 我们可以将这个点的索引设为起点(i,j),当比目标数大时 ...

  2. PythonStudy——列表的常用操作 List of common operations

    # 1.索引取值: 列表名[index] s1 = [1, 3, 2] print(s1[0]) print(s1[-1]) # 2.列表运算: 得到的是新list s2 = [1, 2, 3] pr ...

  3. CSVN配置自动备份策略

    在浏览器中登录CSVN管理页面,登录地址就是ip:3343,版本库->backup schedule ,选择type of job(备份类型),when to run(备份频率和时间),numb ...

  4. 斐波那契数列中获取第n个数据值

    class Fibonacci { /** * Description:迭代方法获取fibonacci第n项数值 * * @param int $n * @return int */ public s ...

  5. 集合总结四(LinkedHashMap的实现原理)

    一.概述 按照惯例,先看一下源码里的第一段注释: Hash table and linked list implementation of the Map interface, with predic ...

  6. 谈谈 ServerFul 架构

    我写了一篇文章 <自己实现一个线程池>  https://www.cnblogs.com/KSongKing/p/9803935.html , 其实 不仅仅 是 线程池, 中间件 层 的 ...

  7. MySQL 列,可选择的数据类型(通过sql命令查看:`help create table;`)

    MySQL 列,可选择的数据类型(通过sql命令查看:help create table;) BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFIL ...

  8. Hello ThreadPoolExecutor

    ThreadPoolExecutor创建: public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliv ...

  9. stm32在linux下使用clion开发

    参考大神的资料,淘宝买了个板子和jlink 几个概念 jlink / openJtag,实现调试协议的硬件 openocd,这个和上面的硬件一起组成调试器 这样有个感性的认识. 具体流程 libusb ...

  10. cordova插件列表

    主要来源为http://blog.csdn.net/github_39500961/article/details/76270299 1.获取当前应用的版本号 cordova plugin add c ...