zoukankan      html  css  js  c++  java
  • 728. Self Dividing Numbers

    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]

    大致意思如下
    一个数如果能被其各位数整除,则称其为自除数,先要求找出一个范围能的自除数

    思路很简单,除以所有自己的各位数即可
    public class selfDividingNumbers {
         public static List<Integer> selfDividingNumbers(int left, int right) {
                List<Integer> result = new ArrayList<Integer>();
                for(int i=left;i<=right;i++)
                {
                    if(!judgeZero(i))
                    {
                        int judge=0;
                        for(int k=0;k<intSize(i).size();k++)
                        {
                            if(i%(intSize(i).get(k))!=0)
                            {
                                judge=1;
                                break;
                            }
                        }
                        if(judge==0)
                        {
                            result.add(i);
                        }
                    }
                }
                return result;
            }
         //判断数字是否含有0
         public static Boolean judgeZero(int judge)
         {
            String temp = String.valueOf(judge);
            if(temp.contains("0"))
            {
                return true;
            }
            else
            {
                return false;
            }
         }
        //获取数字每一位
         public static List<Integer> intSize(int judge)
         {
            String temp = String.valueOf(judge);
             List<Integer> a = new ArrayList<Integer>();
            for(int i=0;i<temp.length();i++)
            {
                char t = temp.charAt(i);
                a.add(Character.getNumericValue(t));
            }
            return a;
         }
         
         public static void main(String args[])
         {
             System.out.println(selfDividingNumbers(100,200).toString());
         }
    }
  • 相关阅读:
    变态跳台阶
    早期(编译器)优化--Java语法糖的味道
    早期(编译器)优化--javac编译器
    虚拟机字节码操作引擎-----基于栈的字节码解释引擎
    虚拟机字节码执行引擎-----方法调用
    虚拟机字节码执行引擎-----运行时栈帧结构
    虚拟机类加载机制--类加载器
    空间索引详解
    svn安装与使用
    IntelliJ IDEA 常用设置 (二)
  • 原文地址:https://www.cnblogs.com/icysnow/p/8126733.html
Copyright © 2011-2022 走看看