[抄题]:

self-dividing number is a number that is divisible by every digit it contains.

For example, 128 is a self-dividing number because 128 % 1 == 0128 % 2 == 0, and 128 % 8 == 0.

Also, a self-dividing number is not allowed to contain the digit zero.

Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.

Example 1:

Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

不知道怎么取出数字中的每一位数:mod%取余,然后每次除10就可以了

[一句话思路]:

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

[画图]:

[一刷]:

  1. 有数字不变的要求:原来的数要固定住,才能自己除以自己

[二刷]:

[三刷]:

[四刷]:

[五刷]:

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

[总结]:

不知道怎么取出数字中的每一位数:mod%取余,然后每次除10就可以了

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

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

取余、除10,很方便

[关键模板化代码]:

[其他解法]:

[Follow Up]:

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

[代码风格] :

class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> res = new LinkedList<Integer>(); for (int i = left; i <= right; i++) {
if (isSelfDividingNumbers(i)) res.add(i);
} return res;
} public boolean isSelfDividingNumbers(int n) {
int original = n;
while (n != 0) {
int res = n % 10;
if (n % 10 == 0) return false;
if (original % res != 0) return false;
n /= 10;
} return true;
}
}

最新文章

  1. 学习 opencv---(6)玩转opencv源代码:生成opencv 工程解决方案与opencv 源码编译
  2. sharepoint2013的审核日志的时间区域设置
  3. 27 GroupSock概述(一)——live555源码阅读(四)网络
  4. matlab函数bwareaopen的详解
  5. [清理页面缓存]asp.net、html
  6. 网络爬虫urllib2 tornado
  7. 关于APP自动化工程的一点小想法
  8. 4 Values whose Sum is 0
  9. Hadoop集群(第10期副刊)_常用MySQL数据库命令
  10. 对于WIFI版ipad(无GPS芯片)定位功能的释疑
  11. [React] React Router: Nested Routes
  12. python接口自动化(十六)--参数关联接口后传(详解)
  13. CentOS7安装MySQL8.0图文教程
  14. 计算pi的位数
  15. jQuery EasyUI 选项卡面板tabs使用实例精讲
  16. MySQL数据库视图(view),视图定义、创建视图、修改视图
  17. 【转】LoadRunner压力测试:测试报告结果分析
  18. SSKeychain
  19. 微信公众号 JSSDK 提示:invalid signature
  20. Docker 技巧:删除 Docker 所有镜像

热门文章

  1. NGINX 配置文件配置url重写
  2. SGU 502 Digits Permutation
  3. bzoj 2657 旅游
  4. HWOJ-求字符串最后一个单词的长度
  5. openid和unionId的区别
  6. 开源的UML建模工具
  7. Delphi使用Indy、ICS组件读取网页
  8. 机器人操作系统(ROS)教程22:ROS的3D可视化工具—rviz
  9. debian下ror新建项目报错解决
  10. Spring缓存源码剖析:(二)CacheManager